diff --git a/main.go b/main.go index 92cd002..d87c0e0 100755 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ func main() { fs.Append(args.STRING, "p", "port to serve", "8100") fs.Append(args.STRING, "u", "user:pass for basic auth", "") fs.Append(args.BOOL, "md", "whether to render markdown as html", true) + fs.Append(args.BOOL, "log", "emit access logs", false) fs.Append(args.BOOL, "ro", "read only mode", false) fs.Append(args.BOOL, "https", "https only", false) fs.Append(args.STRING, "md-css", "css to load for md", "/dev/null") @@ -49,6 +50,7 @@ func main() { https := fs.Get("https").GetBool() mdCss := fs.Get("md-css").GetString() mdClass := fs.Get("md-class").GetString() + accessLogging := fs.GetBool("log") if mdCss != "" { b, err := ioutil.ReadFile(mdCss) if err != nil { @@ -95,15 +97,21 @@ func main() { } p := strings.TrimPrefix(fs.Get("p").GetString(), ":") - http.Handle("/", http.HandlerFunc(handler(userPass, https, ro, d, md, mdCss, mdClass))) + http.Handle("/", http.HandlerFunc(handler(userPass, https, ro, d, md, mdCss, mdClass, accessLogging))) log.Printf("Serving %s on HTTP port: %s\n", d, p) log.Fatal(http.ListenAndServe(":"+p, nil)) } -func handler(userPass string, https, ro bool, d string, md bool, mdCss, mdClass string) http.HandlerFunc { - return httpsOnly(https, gzip(basicAuth(userPass, endpoints(ro, withDel(ro, withMD(d, md, mdCss, mdClass, fserve(d))))))) +func handler(userPass string, https, ro bool, d string, md bool, mdCss, mdClass string, accessLogging bool) http.HandlerFunc { + return withAccessLogging(accessLogging, httpsOnly(https, gzip(basicAuth(userPass, endpoints(ro, withDel(ro, withMD(d, md, mdCss, mdClass, fserve(d)))))))) +} + +func withAccessLogging(enabled bool, h http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + h(w, r) + } } func writeMeta(w http.ResponseWriter) {