(七)静态文件服务
http.FileServer
实现静态文件服务
package main
import (
"fmt"
"net/http"
)
func main() {
fmt.Println("start...")
mux := http.NewServeMux()
files := http.FileServer(http.Dir("./public"))
mux.Handle("/static/", http.StripPrefix("/static/", files))
server := &http.Server{
Addr: "127.0.0.1:1234",
Handler: mux,
}
server.ListenAndServe()
}