I want to create an application that will call a boolean function and depending on the result provide 1 of 2 compiled react apps as static sites.
I'm using the LoadHTMLGlob function recommended by gin and it works fine with .tmpl files like the example in thier docs. However when doing just static html with a static directory for each site nothing seems to go well.
File Structure:
├── main.go
└── sites
├── new
│ ├── index.html
│ └── static
└── old
├── index.html
└── static
Go Code:
func main() {
r := gin.Default()
//r.LoadHTMLFiles("sites/old/index.html", "sites/new/index.html") //doesn't complain, but can't load html
r.LoadHTMLGlob("sites/**/*") // complains about /static being a dir on boot
r.GET("/sites/lib", func(c *gin.Context) {
id := c.Query("id")
useNewSite, err := isBetaUser(id)
if err != nil {
c.AbortWithStatusJSON(500, err.Error())
return
}
if useNewSite {
c.HTML(http.StatusOK, "new/index.html", nil)
} else {
c.HTML(http.StatusOK, "old/index.html", nil)
}
})
routerErr := r.Run(":8080")
if routerErr != nil {
panic(routerErr.Error())
}
}
I expect that when isBetaUser comes back as true it should load the static content under sites/new otherwise load sites/old.
However loading globs produces:
panic: read sites/new/static: is a directory
when starting panics.
Loading the html files individually (commented out above) Runs fine, but when a request comes it panics with:
html/template: "new/index.html" is undefined
I've also string using sites/[old||new]/index.html in c.HTML