Working access logs, .env file loading
This commit is contained in:
parent
a2109224c2
commit
06d85229d7
4
.env.example
Normal file
4
.env.example
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
DATABASE_HOST=
|
||||||
|
DATABASE_USER=
|
||||||
|
DATABASE_PASSWORD=
|
||||||
|
DATABASE_NAME=
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
.idea/*
|
.idea/*
|
||||||
*.swp
|
*.swp
|
||||||
*.log
|
*.log
|
||||||
|
.env
|
||||||
infra-dashboard
|
infra-dashboard
|
||||||
|
|||||||
@ -3,13 +3,30 @@ package http
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
t := time.Now()
|
||||||
|
logRequest(t, r, 200)
|
||||||
fmt.Fprint(w, "Hello, World!")
|
fmt.Fprint(w, "Hello, World!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func HealthHandler(w http.ResponseWriter, _ *http.Request) {
|
func HealthHandler(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, _ = io.WriteString(w, "OK")
|
_, _ = 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(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
args struct {
|
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"`
|
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"`
|
Metrics bool `arg:"--metrics" help:"enable prometheus exporter on /metrics." default:"false"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user