Logger
All checks were successful
release-nightly / build-docker (push) Successful in 1m1s

This commit is contained in:
LittleSheep 2023-11-25 23:06:23 +08:00
parent ad3b36bc2a
commit 3dab1dbd46
3 changed files with 34 additions and 3 deletions

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run RoadSign",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/pkg/cmd/main.go",
"cwd": "${workspaceFolder}"
}
]
}

View File

@ -1,10 +1,13 @@
package administration
import (
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
"fmt"
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
@ -18,6 +21,11 @@ func InitAdministration() *fiber.App {
TrustedProxies: viper.GetStringSlice("security.administration_trusted_proxies"),
})
app.Use(logger.New(logger.Config{
Output: log.Logger,
Format: "[Administration] [${time}] ${status} - ${latency} ${method} ${path}\n",
}))
app.Use(basicauth.New(basicauth.Config{
Realm: fmt.Sprintf("RoadSign v%s", roadsign.AppVersion),
Authorizer: func(_, password string) bool {

View File

@ -1,13 +1,15 @@
package hypertext
import (
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
"fmt"
"time"
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"time"
)
func InitServer() *fiber.App {
@ -20,6 +22,11 @@ func InitServer() *fiber.App {
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
})
app.Use(logger.New(logger.Config{
Output: log.Logger,
Format: "[Proxies] [${time}] ${status} - ${latency} ${method} ${path}\n",
}))
if viper.GetInt("hypertext.limitation.max_qps") > 0 {
app.Use(limiter.New(limiter.Config{
Max: viper.GetInt("hypertext.limitation.max_qps"),