- Download and install it:
$ go get github.com/goframework/gf
- Create server.cfg
Server.Addr = :8016
Server.ReadTimeout = 120
Server.WriteTimeout = 120
Server.MaxHeaderBytes = 65536
Server.StaticDir = ./static
Server.ViewDir = ./view
Server.CookieSecrect = Your cookie secrect (any string)
- Create view/helloworld.html
<!DOCTYPE html>
<html>
<head>
<title>Hello world from GF</title>
</head>
<body>
<p>Hello {{.name}} !</p>
</body>
</html>
- Create main.go
package main
import (
"github.com/goframework/gf"
)
func main() {
gf.HandleGet("/", func(ctx *gf.Context) {
ctx.View = "helloworld.html"
})
gf.HandleGet("/{name}", func(ctx *gf.Context) {
ctx.ViewData["name"] = ctx.RouteVars["name"]
ctx.View = "helloworld.html"
})
gf.Run()
}
- Build, run, then open browser and go to address:
http://localhost:8016
http://localhost:8016/your_name