Created
July 3, 2014 08:34
-
-
Save pinscript/e7e9a00ff2ab40a9252a to your computer and use it in GitHub Desktop.
Gin HTML template example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello world, {{.Name}}! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"html/template" | |
"github.com/gin-gonic/gin" | |
) | |
type Data struct { | |
Name string | |
} | |
func main() { | |
r := gin.Default() | |
html, err := template.ParseFiles("hello.tmpl") | |
if err != nil { | |
panic("Could not parse templates") | |
return | |
} | |
r.HTMLTemplates = html | |
r.GET("/test", func (g *gin.Context) { | |
g.HTML(200, "hello.tmpl", Data{"@dorijastyle"}) | |
}) | |
r.Run(":8082") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesnt work for me..
I manage it like this way:
package main
import (
"github.com/gin-gonic/gin"
)
type Data struct {
Name string
}
func main() {
r := gin.Default()
r.LoadHTMLFiles("hello.tmpl")
r.GET("/test", func(g *gin.Context) {
g.HTML(200, "hello.tmpl", Data{"@dorijastyle"})
})
}