package middleware import ( "context" "github.com/gin-gonic/gin" "github.com/perfect-panel/server/pkg/constant" ) // AdminMetaMiddleware pins the request's client IP and User-Agent onto the // context under constant.CtxKeyIP / constant.CtxKeyUserAgent so downstream // audit writers (admin_action_log) can capture them without threading the // gin.Context through every logic layer. // // This middleware is a no-op for auth: it does NOT gate access; wire it // after AuthMiddleware so ctx.Value(CtxKeyUser) is already populated by the // time an admin logic writes audit rows. func AdminMetaMiddleware() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.Request.Context() ctx = context.WithValue(ctx, constant.CtxKeyIP, c.ClientIP()) ctx = context.WithValue(ctx, constant.CtxKeyUserAgent, c.Request.UserAgent()) c.Request = c.Request.WithContext(ctx) c.Next() } }