Directory Server using Go
2018-02-22
I’ve been spending time learning Go and here’s a small utility I wrote that’s similar to Python’s SimpleHTTPServer.
This utility just creates a small HTTP server serving the directory you define:
package mainimport ( "log" "net/http" "os")func main() { if len(os.Args) < 2 { log.Fatal("You must enter a path") } path := os.Args[1] http.Handle("/", http.FileServer(http.Dir(path))) http.ListenAndServe(":8000", nil)}
package mainimport ( "log" "net/http" "os")func main() { if len(os.Args) < 2 { log.Fatal("You must enter a path") } path := os.Args[1] http.Handle("/", http.FileServer(http.Dir(path))) http.ListenAndServe(":8000", nil)}
Then just do:
go build main.go./serve /etc
go build main.go./serve /etc