forked from TrueCloudLab/frostfs-s3-gw
Refactor if-blocks in GetBearerToken method
This commit is contained in:
parent
ae66e4de61
commit
04dbe30f49
1 changed files with 8 additions and 7 deletions
|
@ -13,14 +13,15 @@ const bearerTokenContextKey contextKey = "bearer-token"
|
|||
|
||||
// GetBearerToken returns a bearer token embedded into a context or error, if any.
|
||||
func GetBearerToken(ctx context.Context) (*service.BearerTokenMsg, error) {
|
||||
if bt := ctx.Value(bearerTokenContextKey); bt != nil {
|
||||
bt := ctx.Value(bearerTokenContextKey)
|
||||
if bt == nil {
|
||||
return nil, errors.New("got nil bearer token")
|
||||
}
|
||||
v, ok := bt.(*service.BearerTokenMsg)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("extracted unexpected type other than bearer token's: %T", v)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
return nil, errors.New("got nil bearer token")
|
||||
}
|
||||
|
||||
// SetBearerToken return a context with embedded bearer token.
|
||||
|
|
Loading…
Reference in a new issue