1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Enable hot-template-reloading in development

This commit is contained in:
Daniel Heath 2018-01-31 14:15:16 +11:00
parent 5e4a317b10
commit c207077877
3 changed files with 19 additions and 5 deletions

View File

@ -2,7 +2,7 @@
# make -j4 release
VERSION=$(shell git describe)
LDFLAGS=-ldflags "-s -w -X main.version=${VERSION}" -a -installsuffix cgo
LDFLAGS=-ldflags "-s -w -X main.version=${VERSION} -X main.hotCodeReloading=false" -a -installsuffix cgo
.PHONY: build
build:
@ -11,8 +11,8 @@ build:
.PHONY: quick
quick:
go-bindata static/... templates/...
go build
go-bindata -debug static/... templates/...
go build -ldflags "-X main.hotCodeReloading=true"
.PHONY: linuxarm
linuxarm:

View File

@ -37,16 +37,28 @@ func serve(
secret string,
secretCode string,
allowInsecure bool,
hotTemplateReloading bool,
) {
if hotTemplateReloading {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
if hotTemplateReloading {
router.LoadHTMLGlob("templates/*.tmpl")
} else {
router.HTMLRender = loadTemplates("index.tmpl")
}
store := sessions.NewCookieStore([]byte(secret))
router.Use(sessions.Sessions("mysession", store))
if secretCode != "" {
router.Use(secretRequired.RequiresSecretAccessCode(secretCode, "/login/"))
}
router.HTMLRender = loadTemplates("index.tmpl")
// router.Use(static.Serve("/static/", static.LocalFile("./static", true)))
router.GET("/", func(c *gin.Context) {
if defaultPage != "" {

View File

@ -9,6 +9,7 @@ import (
)
var version string
var hotTemplateReloading bool
var pathToData string
func main() {
@ -53,6 +54,7 @@ func main() {
c.GlobalString("cookie-secret"),
c.GlobalString("access-code"),
c.GlobalBool("allow-insecure-markup"),
hotTemplateReloading,
)
return nil
}