(七)静态文件服务

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()
}

posted @ 2019-01-03 00:32  yvhqbat  阅读(96)  评论(0编辑  收藏  举报