refactor: use slices.Contains to simplify (#5468)

Signed-off-by: zhedazijingang <unwrap_or_else@outlook.com>
This commit is contained in:
zhedazijingang
2025-08-28 16:25:39 +08:00
committed by GitHub
parent 1bee41ddea
commit 2349ee1eef
4 changed files with 10 additions and 30 deletions

View File

@@ -17,6 +17,7 @@ package token
import (
"fmt"
"net/http"
"slices"
"github.com/golang-jwt/jwt/v5"
"github.com/rs/zerolog/log"
@@ -55,13 +56,7 @@ func Parse(allowedTypes []Type, raw string, fn SecretFunc) (*Token, error) {
return nil, jwt.ErrTokenUnverifiable
}
hasAllowedType := false
for _, k := range allowedTypes {
if k == token.Type {
hasAllowedType = true
break
}
}
hasAllowedType := slices.Contains(allowedTypes, token.Type)
if !hasAllowedType {
return nil, jwt.ErrInvalidType