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));
}
View/home.html
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<center>
<h1>Hello,My name is {{.}}</h1>
</center>
</body>
</html>
有疑问加站长微信联系(非本文作者)