55 "context"
66 "encoding/json"
77 "fmt"
8+ "html/template"
89 "log"
910 "net/http"
1011 "os"
@@ -24,6 +25,7 @@ import (
2425
2526var ginLambda * ginadapter.GinLambdaV2
2627var r * gin.Engine
28+ var indexTmpl * template.Template
2729
2830const (
2931 CHARSET = "UTF-8"
@@ -47,9 +49,9 @@ var s3Client *s3.Client
4749
4850// Build info variables, set via -ldflags at build time
4951var (
50- Version = "dev "
51- BuildTime = "unknown "
52- CommitHash = "none "
52+ Version = "vDev "
53+ BuildTime = "timeless "
54+ CommitHash = "sha-unknown "
5355)
5456
5557// init function runs before main and sets up the Gin router.
@@ -73,8 +75,18 @@ func init() {
7375
7476 r = gin .Default ()
7577 r .Static ("/static" , "./static" )
78+ // Parse index.html once and render as a Go template so we can inject build info
79+ // like the Version string dynamically from the Go build.
80+ indexTmpl = template .Must (template .ParseFiles ("./templates/index.html" ))
7681 r .GET ("/" , func (c * gin.Context ) {
77- c .File ("./static/index.html" )
82+ data := struct { Version string }{Version : Version }
83+ var buf bytes.Buffer
84+ if err := indexTmpl .Execute (& buf , data ); err != nil {
85+ log .Printf ("failed to render index template: %v" , err )
86+ c .String (http .StatusInternalServerError , "Internal Server Error" )
87+ return
88+ }
89+ c .Data (http .StatusOK , "text/html; charset=utf-8" , buf .Bytes ())
7890 })
7991 r .GET ("/favicon.ico" , func (c * gin.Context ) {
8092 c .File ("./static/favicon.ico" )
0 commit comments