badlyenginee.red

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 main
import (
"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 main
import (
"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