diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7f58942 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +DATABASE_HOST= +DATABASE_USER= +DATABASE_PASSWORD= +DATABASE_NAME= diff --git a/.gitignore b/.gitignore index cc6bb6a..3df1fa5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/* *.swp *.log +.env infra-dashboard diff --git a/Http/utils.go b/Http/utils.go index 706adce..575679b 100644 --- a/Http/utils.go +++ b/Http/utils.go @@ -3,13 +3,30 @@ package http import ( "fmt" "io" + "log" "net/http" + "time" ) func RequestHandler(w http.ResponseWriter, r *http.Request) { + t := time.Now() + logRequest(t, r, 200) fmt.Fprint(w, "Hello, World!") } func HealthHandler(w http.ResponseWriter, _ *http.Request) { _, _ = io.WriteString(w, "OK") } + +func logRequest(t time.Time, r *http.Request, s int) { + log.Printf("%s - - %s \"%s %s %s\" %d 0 \"-\" \"%s\" %d\n", + r.Host, + t.Format("[02/Jan/2006:15:04:05 -0700]"), + r.Method, + r.URL.Path, + r.Proto, + s, + r.UserAgent(), + time.Since(t).Milliseconds(), + ) +} diff --git a/main.go b/main.go index e6078eb..b2333b6 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( var ( args struct { - Log string `arg:"-l,--logfile" help:"location of output logfile." default:"/app/http-broadcaster.log"` + Log string `arg:"-l,--logfile" help:"location of output logfile." default:"infra-dashboard-access.log"` EnvFile string `arg:"-e,--envfile" help:"location of file containing environment variables." default:".env"` Metrics bool `arg:"--metrics" help:"enable prometheus exporter on /metrics." default:"false"` }