HTML files templates 9 – Gin Gonic Golang Web Framework
HTML files templates 9 – Gin Gonic Golang Web Framework
Source Code
[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”]// working with html files and sending data
// dynamic pages
package main
import "github.com/gin-gonic/gin"
func main() {
// create new router/server
r := gin.Default()
// lets create our first route for files
r.LoadHTMLGlob("./templates/*")
// it mean all our html template will be in templates folder
// lets create our Get request routes home, about and contact us
r.GET("/", func(c *gin.Context) {
c.HTML(200, "index.tmpl", map[string]string{"title": "home page"})
// status code // our html file name // data we want to send
// copy and paste for other 2
})
// contact us
r.GET("/contact", func(c *gin.Context) {
c.HTML(200, "index.tmpl", map[string]string{"title": "contact us page"})
// status code // our html file name // data we want to send
// copy and paste for other 2
})
// about us page
r.GET("/about", func(c *gin.Context) {
c.HTML(200, "index.tmpl", map[string]string{"title": "about page"})
// status code // our html file name // data we want to send
// copy and paste for other 2
})
// lets create our template folder and html file
r.Run()
}
[/sourcecode]
golang gingonic framework videos tutorials series
TAGS#
gin gonic tutorial
gin-gonic / examples
gin-gonic documentation
gin framework tutorial
gin web framework
gin router
golang gin context
gin router group
###Buy Me a Coffee https://www.buymeacoffee.com/khan1