diff --git a/web/auth/context.go b/web/auth/context.go index 0e92e38..004c0ad 100644 --- a/web/auth/context.go +++ b/web/auth/context.go @@ -1,7 +1,5 @@ package auth -import "platform/pkg/u" - // Context 定义认证信息 type Context struct { Payload Payload `json:"payload"` @@ -39,8 +37,9 @@ type Agent struct { type PayloadType int const ( + PayloadNone PayloadType = iota // PayloadUser 用户类型 - PayloadUser PayloadType = iota + 1 + PayloadUser // PayloadAdmin 管理员类型 PayloadAdmin // PayloadClientPublic 公共客户端类型 @@ -59,20 +58,22 @@ func (t PayloadType) ToStr() string { return "cpub" case PayloadClientConfidential: return "ccnf" + default: + return "none" } - return "none" } -func PayloadTypeFromStr(name string) *PayloadType { +func PayloadTypeFromStr(name string) PayloadType { switch name { case "user": - return u.P(PayloadUser) + return PayloadUser case "admn": - return u.P(PayloadAdmin) + return PayloadAdmin case "cpub": - return u.P(PayloadClientPublic) + return PayloadClientPublic case "ccnf": - return u.P(PayloadClientConfidential) + return PayloadClientConfidential + default: + return PayloadNone } - return nil } diff --git a/web/web.go b/web/web.go index e44ab6d..32dd94c 100644 --- a/web/web.go +++ b/web/web.go @@ -114,6 +114,11 @@ func useLogger() fiber.Handler { Format: "🚀 ${time} | ${locals:authtype} ${locals:authid} | ${method} ${path} | ${status} | ${latency} | ${error}\n", TimeFormat: "2006-01-02 15:04:05", TimeZone: "Asia/Shanghai", + Next: func(c *fiber.Ctx) bool { + c.Locals("authtype", auth.PayloadNone.ToStr()) + c.Locals("authid", 0) + return false + }, Done: func(c *fiber.Ctx, logBytes []byte) { var logStr = strings.TrimPrefix(string(logBytes), "🚀") var logVars = strings.Split(logStr, "|") @@ -147,8 +152,8 @@ func useLogger() fiber.Handler { Error: errStr, Time: core.LocalDateTime(reqTime), } - if authType != nil { - item.Identity = int32(*authType) + if authType != auth.PayloadNone { + item.Identity = int32(authType) } if authID != 0 { item.Visitor = int32(authID)