package main import ( "fmt" "net/http" "flag" "path/filepath" log "github.com/sirupsen/logrus" ) func main() { log.SetFormatter(&log.TextFormatter{ FullTimestamp: true, }); pathFlag := flag.String( "path", "data", "the path to load site data from", ); addrFlag := flag.String( "addr", "127.0.0.1:8080", "the address to serve from", ); flag.Parse(); log.Infof("data path: %v", *pathFlag); log.Infof("serving from %v", *addrFlag); mux := http.NewServeMux() mux.HandleFunc("/ip", func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "%v", req.RemoteAddr); }); mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { if req.URL.Path != "/" { path := filepath.Join(*pathFlag, req.URL.Path); Serve(w, req, path); } else { Serve(w, req, filepath.Join(*pathFlag, "index.md")); } }); server := http.Server{ Addr: *addrFlag, Handler: mux, }; err := server.ListenAndServe(); if err != nil { log.Fatal(err); } }