funcmain() { log.Printf("server listen at [%v]:[%v] and document root is [%v]\n", host, port, path) log.Println(path) fs := http.FileServer(http.Dir(path)) http.Handle("/", fs) http.ListenAndServe(fmt.Sprintf("%v:%v", host, port), nil) }
使用
查看帮助 gohttpserver.exe -h
1 2 3 4 5 6 7 8
$ gohttpserver.exe -h Usage of gohttpserver.exe: -host string host ip address (default "0.0.0.0") -path string server document root (default "./") -port int server port listen (default 8000)