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:
parent
5e4a317b10
commit
c207077877
6
Makefile
6
Makefile
@ -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:
|
||||
|
16
handlers.go
16
handlers.go
@ -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)
|
||||
}
|
||||
|
||||
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 != "" {
|
||||
|
2
main.go
2
main.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user