Skip to content

Instantly share code, notes, and snippets.

@jself
Created November 8, 2013 23:07
Show Gist options
  • Save jself/7379104 to your computer and use it in GitHub Desktop.
Save jself/7379104 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
)
func main() {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
os.Exit(-1)
}
var portn = flag.Int("port", 8080, "The port to run the server on")
flag.Parse()
var port = fmt.Sprintf(":%d", *portn)
fmt.Println("Running server for", dir, "and port", port)
panic(http.ListenAndServe(port, http.FileServer(http.Dir(dir))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment