// A static file server written in Go. package main import ( "flag" "fmt" "log" "net/http" "os" ) type Options struct { // The port on which the server should listen. Port int // The address on which the server should listen. Host string } func main() { var options Options flag.IntVar(&options.Port, "port", 3000, "the port on which to listen") flag.StringVar(&options.Host, "host", "localhost", "the host on which to listen") flag.Parse() var dir string var err error if len(flag.Args()) > 0 { dir = flag.Arg(0) } else { dir, err = os.Getwd() if err != nil { log.Fatal("cannot determine current working directory") } } fs := http.FileServer(http.Dir(dir)) http.Handle("/", fs) log.Printf("Listening on %s:%d...\n", options.Host, options.Port) http.ListenAndServe(fmt.Sprintf(":%d", options.Port), nil) }