mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-15 15:31:16 +00:00
22 lines
357 B
Go
22 lines
357 B
Go
package middleware
|
|
|
|
import (
|
|
"nysoure/server/stat"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
func StatMiddleware(c fiber.Ctx) error {
|
|
err := c.Next()
|
|
status := "200"
|
|
if err != nil {
|
|
if e, ok := err.(*fiber.Error); ok {
|
|
status = string(rune(e.Code))
|
|
} else {
|
|
status = "500"
|
|
}
|
|
}
|
|
stat.RecordRequest(c.Method(), c.Route().Path, status)
|
|
return err
|
|
}
|