diff --git a/components/core/html.templ b/components/core/html.templ deleted file mode 100644 index dd02d77..0000000 --- a/components/core/html.templ +++ /dev/null @@ -1,30 +0,0 @@ -package core - -import "vctp/version" - -templ HTML(title string, content templ.Component) { - - - @head(title) - @body(content) - -} - -templ head(title string) { - - - - - { title } - - - -} - -templ body(content templ.Component) { - -
- @content -
- -} diff --git a/components/core/html_templ.go b/components/core/html_templ.go deleted file mode 100644 index 3e4d22e..0000000 --- a/components/core/html_templ.go +++ /dev/null @@ -1,137 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.771 -package core - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import templruntime "github.com/a-h/templ/runtime" - -import "vctp/version" - -func HTML(title string, content templ.Component) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = head(title).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = body(content).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -func head(title string) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var2 := templ.GetChildren(ctx) - if templ_7745c5c3_Var2 == nil { - templ_7745c5c3_Var2 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(title) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/html.templ`, Line: 18, Col: 16} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -func body(content templ.Component) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var5 := templ.GetChildren(ctx) - if templ_7745c5c3_Var5 == nil { - templ_7745c5c3_Var5 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = content.Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/components/home/home.templ b/components/home/home.templ index 809175e..654e89e 100644 --- a/components/home/home.templ +++ b/components/home/home.templ @@ -1,9 +1,18 @@ package home -templ Home() { -
-

Welcome!

-

This is a simple home screen.

-

{ buildTime }

-
-} +// Define the Home template, accepting a BuildInfo struct. +templ Home(buildTime string, sha1ver string, goVersion string) { + + + + + Build Information + + +

Build Information

+

Build Time: {buildTime}

+

SHA1 Version: {sha1ver}

+

Go Runtime Version: {goVersion}

+ + +} \ No newline at end of file diff --git a/components/home/home_templ.go b/components/home/home_templ.go index 6460656..47cc253 100644 --- a/components/home/home_templ.go +++ b/components/home/home_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.771 +// templ: version: v0.2.778 package home //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -8,9 +8,13 @@ package home import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -func Home() templ.Component { +// Define the Home template, accepting a BuildInfo struct. +func Home(buildTime string, sha1ver string, goVersion string) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { defer func() { @@ -26,7 +30,46 @@ func Home() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Welcome!

This is a simple home screen.

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Build Information

Build Information

Build Time: ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(buildTime) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `home/home.templ`, Line: 13, Col: 54} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

SHA1 Version: ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(sha1ver) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `home/home.templ`, Line: 14, Col: 54} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Go Runtime Version: ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(goVersion) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `home/home.templ`, Line: 15, Col: 62} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/main.go b/main.go index b9662c3..893a301 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "os" + "runtime" "time" "vctp/db" "vctp/internal/tasks" @@ -141,7 +142,7 @@ func main() { s, cancel, bindAddress, - server.WithRouter(router.New(logger, database)), + server.WithRouter(router.New(logger, database, buildTime, sha1ver, runtime.Version())), ) svr.DisableTls(bindDisableTls) diff --git a/server/handler/handler.go b/server/handler/handler.go index 8dfaea7..164775d 100644 --- a/server/handler/handler.go +++ b/server/handler/handler.go @@ -2,16 +2,20 @@ package handler import ( "context" - "github.com/a-h/templ" - "vctp/db" "log/slog" "net/http" + "vctp/db" + + "github.com/a-h/templ" ) // Handler handles requests. type Handler struct { - Logger *slog.Logger - Database db.Database + Logger *slog.Logger + Database db.Database + BuildTime string + SHA1Ver string + GoVersion string } func (h *Handler) html(ctx context.Context, w http.ResponseWriter, status int, t templ.Component) { diff --git a/server/handler/home.go b/server/handler/home.go index c6ee346..b023389 100644 --- a/server/handler/home.go +++ b/server/handler/home.go @@ -2,11 +2,17 @@ package handler import ( "net/http" - "vctp/components/core" "vctp/components/home" ) // Home handles the home page. func (h *Handler) Home(w http.ResponseWriter, r *http.Request) { - h.html(r.Context(), w, http.StatusOK, core.HTML("Example Site", home.Home())) + //h.html(r.Context(), w, http.StatusOK, core.HTML("Example Site", home.Home())) + + // Render the template + err := home.Home(h.BuildTime, h.SHA1Ver, h.GoVersion).Render(r.Context(), w) + if err != nil { + http.Error(w, "Failed to render template", http.StatusInternalServerError) + } + } diff --git a/server/router/router.go b/server/router/router.go index 2b8ead4..c36b3e0 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -9,10 +9,13 @@ import ( "vctp/server/middleware" ) -func New(logger *slog.Logger, database db.Database) http.Handler { +func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver string, goVersion string) http.Handler { h := &handler.Handler{ - Logger: logger, - Database: database, + Logger: logger, + Database: database, + BuildTime: buildTime, + SHA1Ver: sha1ver, + GoVersion: goVersion, } mux := http.NewServeMux()