Skip to content

Instantly share code, notes, and snippets.

@pinscript
Created July 3, 2014 08:34
Show Gist options
  • Save pinscript/e7e9a00ff2ab40a9252a to your computer and use it in GitHub Desktop.
Save pinscript/e7e9a00ff2ab40a9252a to your computer and use it in GitHub Desktop.
Gin HTML template example
Hello world, {{.Name}}!
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")
}
@cention-mujibur-rahman
Copy link

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"})
})

r.Run(":8082")

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment