body
{
background-color:#d0e4fe;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
package main
import (
"github.com/gorilla/mux"
"html/template" //模板包
"net/http"
)
var (
//申明模板变量,自动引入模板包
templates *template.Template
)
func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
//普通路由
r.HandleFunc("/index", cssHandler)
fs := http.FileServer(http.Dir("./static"))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static", fs))
http.ListenAndServe(":8080", r)
}
func cssHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
templates.ExecuteTemplate(w, "css.html", nil)
}