1 回答
TA贡献1816条经验 获得超4个赞
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>
- 1 回答
- 0 关注
- 162 浏览
添加回答
举报