refactor: upgrade to Go 1.26 and modernize code idioms
- Replace `interface{}` with `any` type alias across all packages
- Use built-in `min()`/`max()` for parameter clamping
- Use `slices.SortFunc`, `slices.Min`, `slices.Max` for cleaner code
- Use `strings.Cut()` for simpler string parsing in auth middleware
- Use `errors.Is()` for proper error comparison in handlers
- Update dependencies: golang.org/x/image 0.37.0 -> 0.38.0
- Add Wire code generation guidelines to ARCHITECTURE.md
- Disable Go cache in CI build workflow
This commit is contained in:
@@ -21,15 +21,13 @@ func Auth(jwtService *service.JWTService) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// 提取Token
|
||||
parts := strings.SplitN(authHeader, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
prefix, token, found := strings.Cut(authHeader, " ")
|
||||
if !found || prefix != "Bearer" {
|
||||
response.Unauthorized(c, "invalid authorization header format")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
token := parts[1]
|
||||
|
||||
// 验证Token
|
||||
claims, err := jwtService.ParseToken(token)
|
||||
if err != nil {
|
||||
@@ -56,14 +54,12 @@ func OptionalAuth(jwtService *service.JWTService) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// 提取Token
|
||||
parts := strings.SplitN(authHeader, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
prefix, token, found := strings.Cut(authHeader, " ")
|
||||
if !found || prefix != "Bearer" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
token := parts[1]
|
||||
|
||||
// 验证Token
|
||||
claims, err := jwtService.ParseToken(token)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user