├── static-http ├── README └── main.go /static-http: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlricQin/static-http/master/static-http -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 我们经常有这样的需求,某个目录下的内容想用http的方式暴露出来,方便别人下载,这个static-http就是为此而生 2 | 3 | 通常要把static-http加入PATH,这样在任意目录都可以用了 4 | 5 | cd到你要作为http的目录,static-http 8888 即可,不加端口的话默认会使用8888端口 6 | 7 | 当前目录中的static-http是在amd_x64的Linux机器上面编译的,如果你是其他平台,则需要重新编译了,代码很简单,只有一个 `main.go` 8 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | "runtime" 8 | ) 9 | 10 | func main() { 11 | args := os.Args 12 | l := len(args) 13 | 14 | pwd, err := os.Getwd() 15 | if err != nil { 16 | fmt.Fprintf(os.Stderr, "os.Getwd() fail. error: %s", err) 17 | os.Exit(1) 18 | } 19 | 20 | port := "8888" 21 | if l == 2 { 22 | // http port given 23 | port = args[1] 24 | } 25 | 26 | runtime.GOMAXPROCS(runtime.NumCPU()) 27 | 28 | fmt.Printf("static http server serve at: %s ...\n", port) 29 | panic(http.ListenAndServe(":"+port, http.FileServer(http.Dir(pwd)))) 30 | } 31 | --------------------------------------------------------------------------------