(七)静态文件服务

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

猜你喜欢

转载自www.cnblogs.com/walkinginthesun/p/10212075.html
今日推荐