This commit is contained in:
oneao committed 2026-02-25 22:20:16 +08:00
1 parent d04d22723b
commit 4ce951dd56
30 files changed
+982 -74

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
package handler
import (
"allapp/utils/jwtx"
"github.com/gofiber/fiber/v3"
)
// Hello handle api status
func Hello(c fiber.Ctx) error {
return c.JSON(fiber.Map{"status": "success", "message": "Hello i'm ok!", "data": nil})
}
@@ -0,0 +1,33 @@
package middleware
import (
"context"
"time"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/log"
)
func Logger() fiber.Handler {
return func(c fiber.Ctx) error {
ctx := context.WithValue(c.Context(), "request_id", c.RequestID())
c.SetContext(ctx)
start := time.Now()
err := c.Next()
duration := time.Since(start)
// 记录日志
log.WithContext(c.Context()).Infow("API Request",
"method", c.Method(),
"path", c.Path(),
"status", c.Response().StatusCode(),
"duration", duration.String(),
"ip", c.IP(),
)
return err
}
}
@@ -0,0 +1,14 @@
package router
import (
"allapp/api/handler"
"allapp/config"
"github.com/gofiber/fiber/v3"
)
func SetupRouters(app *fiber.App) {
api := app.Group(config.GetConf().Server.BaseUrl)
api.Get("/", handler.Hello)
}