example: Replace interface{} with any

Signed-off-by: Thomas Hipp <thomashipp@gmail.com>
This commit is contained in:
Thomas Hipp 2023-09-26 19:51:56 +02:00
parent ceaf2b184d
commit cb2aa5c0f8
No known key found for this signature in database
GPG key ID: 36F3DB891755E09B
3 changed files with 15 additions and 15 deletions

View file

@ -125,7 +125,7 @@ func main() {
testURL := r.Form.Get("url") testURL := r.Form.Get("url")
var data struct { var data struct {
URL string URL string
Response interface{} Response any
} }
if testURL != "" { if testURL != "" {
data.URL = testURL data.URL = testURL
@ -149,7 +149,7 @@ func main() {
logrus.Fatal(http.ListenAndServe("127.0.0.1:"+port, nil)) logrus.Fatal(http.ListenAndServe("127.0.0.1:"+port, nil))
} }
func callExampleEndpoint(client *http.Client, testURL string) (interface{}, error) { func callExampleEndpoint(client *http.Client, testURL string) (any, error) {
req, err := http.NewRequest("GET", testURL, nil) req, err := http.NewRequest("GET", testURL, nil)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -61,7 +61,7 @@ func (s *signingKey) SignatureAlgorithm() jose.SignatureAlgorithm {
return s.algorithm return s.algorithm
} }
func (s *signingKey) Key() interface{} { func (s *signingKey) Key() any {
return s.key return s.key
} }
@ -85,7 +85,7 @@ func (s *publicKey) Use() string {
return "sig" return "sig"
} }
func (s *publicKey) Key() interface{} { func (s *publicKey) Key() any {
return &s.key.PublicKey return &s.key.PublicKey
} }
@ -525,11 +525,11 @@ func (s *Storage) SetIntrospectionFromToken(ctx context.Context, introspection *
// GetPrivateClaimsFromScopes implements the op.Storage interface // GetPrivateClaimsFromScopes implements the op.Storage interface
// it will be called for the creation of a JWT access token to assert claims for custom scopes // it will be called for the creation of a JWT access token to assert claims for custom scopes
func (s *Storage) GetPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (claims map[string]interface{}, err error) { func (s *Storage) GetPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (claims map[string]any, err error) {
return s.getPrivateClaimsFromScopes(ctx, userID, clientID, scopes) return s.getPrivateClaimsFromScopes(ctx, userID, clientID, scopes)
} }
func (s *Storage) getPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (claims map[string]interface{}, err error) { func (s *Storage) getPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (claims map[string]any, err error) {
for _, scope := range scopes { for _, scope := range scopes {
switch scope { switch scope {
case CustomScope: case CustomScope:
@ -713,7 +713,7 @@ func (s *Storage) CreateTokenExchangeRequest(ctx context.Context, request op.Tok
// GetPrivateClaimsFromScopesForTokenExchange implements the op.TokenExchangeStorage interface // GetPrivateClaimsFromScopesForTokenExchange implements the op.TokenExchangeStorage interface
// it will be called for the creation of an exchanged JWT access token to assert claims for custom scopes // it will be called for the creation of an exchanged JWT access token to assert claims for custom scopes
// plus adding token exchange specific claims related to delegation or impersonation // plus adding token exchange specific claims related to delegation or impersonation
func (s *Storage) GetPrivateClaimsFromTokenExchangeRequest(ctx context.Context, request op.TokenExchangeRequest) (claims map[string]interface{}, err error) { func (s *Storage) GetPrivateClaimsFromTokenExchangeRequest(ctx context.Context, request op.TokenExchangeRequest) (claims map[string]any, err error) {
claims, err = s.getPrivateClaimsFromScopes(ctx, "", request.GetClientID(), request.GetScopes()) claims, err = s.getPrivateClaimsFromScopes(ctx, "", request.GetClientID(), request.GetScopes())
if err != nil { if err != nil {
return nil, err return nil, err
@ -742,12 +742,12 @@ func (s *Storage) SetUserinfoFromTokenExchangeRequest(ctx context.Context, useri
return nil return nil
} }
func (s *Storage) getTokenExchangeClaims(ctx context.Context, request op.TokenExchangeRequest) (claims map[string]interface{}) { func (s *Storage) getTokenExchangeClaims(ctx context.Context, request op.TokenExchangeRequest) (claims map[string]any) {
for _, scope := range request.GetScopes() { for _, scope := range request.GetScopes() {
switch { switch {
case strings.HasPrefix(scope, CustomScopeImpersonatePrefix) && request.GetExchangeActor() == "": case strings.HasPrefix(scope, CustomScopeImpersonatePrefix) && request.GetExchangeActor() == "":
// Set actor subject claim for impersonation flow // Set actor subject claim for impersonation flow
claims = appendClaim(claims, "act", map[string]interface{}{ claims = appendClaim(claims, "act", map[string]any{
"sub": request.GetExchangeSubject(), "sub": request.GetExchangeSubject(),
}) })
} }
@ -755,7 +755,7 @@ func (s *Storage) getTokenExchangeClaims(ctx context.Context, request op.TokenEx
// Set actor subject claim for delegation flow // Set actor subject claim for delegation flow
// if request.GetExchangeActor() != "" { // if request.GetExchangeActor() != "" {
// claims = appendClaim(claims, "act", map[string]interface{}{ // claims = appendClaim(claims, "act", map[string]any{
// "sub": request.GetExchangeActor(), // "sub": request.GetExchangeActor(),
// }) // })
// } // }
@ -777,16 +777,16 @@ func getInfoFromRequest(req op.TokenRequest) (clientID string, authTime time.Tim
} }
// customClaim demonstrates how to return custom claims based on provided information // customClaim demonstrates how to return custom claims based on provided information
func customClaim(clientID string) map[string]interface{} { func customClaim(clientID string) map[string]any {
return map[string]interface{}{ return map[string]any{
"client": clientID, "client": clientID,
"other": "stuff", "other": "stuff",
} }
} }
func appendClaim(claims map[string]interface{}, claim string, value interface{}) map[string]interface{} { func appendClaim(claims map[string]any, claim string, value any) map[string]any {
if claims == nil { if claims == nil {
claims = make(map[string]interface{}) claims = make(map[string]any)
} }
claims[claim] = value claims[claim] = value
return claims return claims

View file

@ -239,7 +239,7 @@ func (s *multiStorage) SetIntrospectionFromToken(ctx context.Context, introspect
// GetPrivateClaimsFromScopes implements the op.Storage interface // GetPrivateClaimsFromScopes implements the op.Storage interface
// it will be called for the creation of a JWT access token to assert claims for custom scopes // it will be called for the creation of a JWT access token to assert claims for custom scopes
func (s *multiStorage) GetPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (claims map[string]interface{}, err error) { func (s *multiStorage) GetPrivateClaimsFromScopes(ctx context.Context, userID, clientID string, scopes []string) (claims map[string]any, err error) {
storage, err := s.storageFromContext(ctx) storage, err := s.storageFromContext(ctx)
if err != nil { if err != nil {
return nil, err return nil, err