1. 程式人生 > >(七)靜態檔案服務

(七)靜態檔案服務

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