繁华开满天机
import ( "fmt" "net/http" "text/template")type Portal struct{ Title string}func main(){ //Create MUX Routing handlers http.HandleFunc("/", portal) //Start WebServer if err := http.ListenAndServe(":1234", nil); err != nil{ panic(err) }}func portal(w http.ResponseWriter, r *http.Request){ //Create template tmpl, _ := template.ParseFiles("./html_templates/portal.html") //Populate struct portal := Portal{ Title: "title", } //Execute template with struct data tmpl.Execute(w, portal)}以及相关的 HTML:<html><head> <title>{{ .Title }}</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> @font-face { font-family: 'comfortaaRegular'; src: url('Comfortaa-Regular.ttf'); src: local('comfortaaRegular'), local('Comfortaa-Regular.ttf'), url('Comfortaa-Regular.ttf') format('truetype'), } body{ font-family: 'comfortaaRegular' } </style></head><body> <p>test/p></body></html>