Skip to content

Instantly share code, notes, and snippets.

@nl5887
Last active October 10, 2017 11:09
Show Gist options
  • Save nl5887/8aaee404c6bef30d23eb to your computer and use it in GitHub Desktop.
Save nl5887/8aaee404c6bef30d23eb to your computer and use it in GitHub Desktop.
Extreme simple (golang) webserver to serve static files. Easy for testing.
package main
import (
"flag"
"fmt"
"net/http"
)
func main() {
path := flag.String("path", ".", "path to static files")
port := flag.String("port", "8080", "port number, default: 8080")
flag.Parse()
fmt.Printf("Super simple static server started.\nListening on 127.0.0.1:%s, serving path \"%s\".\n", *port, *path)
fmt.Printf("---------------------------\n")
panic(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%s", *port), http.FileServer(http.Dir(*path))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment