This is a creation in Article, where the information may have evolved or changed.
Objective
Learn about developing Web apps with Go template technology.
Effect
Code
Server.go
Package main
Import (
fmt
http
&nbs p; "template"
)
type User struct {
name string
}
Func Register (w http. Responsewriter, R *http. Request) {
if ' GET ' = = r.method {
fmt. Fprintln (W, "
Register" +
"")
&nb sp; return
}
User: = &user{r.formval UE ("UserName")}
T, _: = template. Parsefile ("hello.html", nil)
t.execute (w, user)
}
Func Main () {
http. Handlefunc ("/", Register)
http. Listenandserve (": 8080", nil)
}
Hello.html
Hello, {Name}
Summarize
- Automatically resolve type fields
- Templates need to be self-programmed for caching
Next
This article is to use B3log Solo from the simple design of the art of synchronous release of the original address: http://88250.b3log.org/go-web-2.html