diff --git a/go.mod b/go.mod index b62b46c..573eb16 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,14 @@ module gogs.inhome.blapointe.com/local/simpleserve -go 1.16 +go 1.18 require ( gogs.inhome.blapointe.com/local/args v0.0.0-20230410154220-44370f257b34 gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc gogs.inhome.blapointe.com/local/notes-server v0.0.0-20230410171406-a4d39d38dc55 ) + +require ( + github.com/gomarkdown/markdown v0.0.0-20220607163217-45f7c050e2d1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/main.go b/main.go index d87c0e0..26272c2 100755 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/json" "errors" "fmt" "io" @@ -13,6 +14,7 @@ import ( "path" "regexp" "strings" + "time" "gogs.inhome.blapointe.com/local/args" "gogs.inhome.blapointe.com/local/gziphttp" @@ -110,6 +112,23 @@ func handler(userPass string, https, ro bool, d string, md bool, mdCss, mdClass func withAccessLogging(enabled bool, h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + if r.URL.Host == "" { + r.URL.Host = r.Host + } + b, _ := json.Marshal(map[string]any{ + "_ts": time.Now(), + "client": map[string]any{ + "ip": r.RemoteAddr, + "forwarded-for": r.Header.Get("X-Forwarded-For"), + "user-agent": r.UserAgent(), + }, + "request": map[string]any{ + "method": r.Method, + "url": r.URL.String(), + "headers": r.Header, + }, + }) + fmt.Printf("%s\n", b) h(w, r) } }