Generally improves locking and logging

This commit is contained in:
Daniel Svitan 2025-05-08 12:52:31 +02:00
parent b31382fcda
commit a23632d5df

10
main.go
View File

@ -58,6 +58,7 @@ func main() {
app := echo.New()
app.Logger.SetLevel(log.INFO)
log.SetLevel(log.INFO)
app.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
StackSize: 1 << 10,
@ -69,6 +70,7 @@ func main() {
Format: "${time_custom} ${method} ${uri} ---> ${status} in ${latency_human} (${bytes_out} bytes)\n",
CustomTimeFormat: TimeFormat,
}))
log.SetHeader("${time_rfc3339} ${level}")
app.Use(middleware.RemoveTrailingSlash())
app.OnAddRouteHandler = func(host string, route echo.Route, handler echo.HandlerFunc, middleware []echo.MiddlewareFunc) {
@ -141,6 +143,14 @@ func main() {
return c.NoContent(http.StatusOK)
}))
app.GET("/locked", authed(func(c echo.Context) error {
mut.Lock()
l := locked
mut.Unlock()
return c.JSON(http.StatusOK, l)
}))
app.POST("/lock", authed(func(c echo.Context) error {
mut.Lock()
locked = true