golang 如何使用模版?
发布时间:2020-12-16 09:35:27 所属栏目:大数据 来源:网络整理
导读:package mainimport ( "fmt" "net/http" "log" "html/template")func main () { //实例化一个 HTTP app := http.NewServeMux(); app.HandleFunc("/",func(w http.ResponseWriter,r *http.Request){ switch r.Method { case "GET": tmpl,_ := template.ParseF
package main import ( "fmt" "net/http" "log" "html/template" ) func main () { //实例化一个 HTTP app := http.NewServeMux(); app.HandleFunc("/",func(w http.ResponseWriter,r *http.Request){ switch r.Method { case "GET": tmpl,_ := template.ParseFiles("./View/home.html"); tmpl.Execute(w,"Master"); case "POST": case "PUT": case "DELETE": default: } }); address := "127.0.0.1:80" fmt.Printf("Application: running using host(http://%s) n",address); log.Fatal(http.ListenAndServe(address,app)); }
<html> <head> <title>Hello World!</title> </head> <body> <center> <h1>Hello,My name is {{.}}</h1> </center> </body> </html> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |