feature (dynamic): make configuration dynamic

This commit is contained in:
MickaelK
2024-03-12 23:52:16 +11:00
parent 845c4584d3
commit 9e142d5de5
31 changed files with 631 additions and 542 deletions

View File

@ -9,6 +9,19 @@ import (
"time"
)
var telemetry = Telemetry{Data: make([]LogEntry, 0)}
func init() {
Hooks.Register.Onload(func() {
go func() {
for {
time.Sleep(10 * time.Second)
telemetry.Flush()
}
}()
})
}
type Middleware func(func(*App, http.ResponseWriter, *http.Request)) func(*App, http.ResponseWriter, *http.Request)
func NewMiddlewareChain(fn func(*App, http.ResponseWriter, *http.Request), m []Middleware, app App) http.HandlerFunc {
@ -108,7 +121,7 @@ func Logger(ctx App, res http.ResponseWriter, req *http.Request) {
RequestID: func() string {
defer func() string {
if r := recover(); r != nil {
Log.Debug("middleware::index get header '%s'", r)
return "oops"
}
return "null"
}()
@ -161,14 +174,3 @@ func (this *Telemetry) Flush() {
}
resp.Body.Close()
}
var telemetry Telemetry = Telemetry{Data: make([]LogEntry, 0)}
func init() {
go func() {
for {
time.Sleep(10 * time.Second)
telemetry.Flush()
}
}()
}