瀏覽代碼

static root file server support configurable URL and strip prefix

master
sp 5 年之前
父節點
當前提交
eb50cea655
共有 3 個文件被更改,包括 9 次插入5 次删除
  1. +5
    -3
      config.go
  2. +3
    -1
      config.json
  3. +1
    -1
      main.go

+ 5
- 3
config.go 查看文件

) )


type configuration struct { type configuration struct {
Host string
Port string
DocRoot string
Host string
Port string
DocRoot string
StaticUrl string
StripPrefix string
} }


var configFile = "config.json" var configFile = "config.json"

+ 3
- 1
config.json 查看文件

{ {
"Host":"127.0.0.1", "Host":"127.0.0.1",
"Port":"8080", "Port":"8080",
"DocRoot": "./html/"
"DocRoot": "./html/",
"StaticUrl": "/",
"StripPrefix" : "/"
} }

+ 1
- 1
main.go 查看文件

func setupRootFileServer() { func setupRootFileServer() {


fs := http.FileServer(http.Dir(config.DocRoot)) fs := http.FileServer(http.Dir(config.DocRoot))
http.Handle("/", http.StripPrefix("/", fs))
http.Handle(config.StaticUrl, http.StripPrefix(config.StripPrefix, fs))


} }



Loading…
取消
儲存