use plain pkg module
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
committed by
Florian Schade
parent
259cbc2e56
commit
b07b5a1149
@@ -0,0 +1,22 @@
|
||||
package roles
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/opencloud-eu/opencloud/pkg/middleware"
|
||||
"go-micro.dev/v4/metadata"
|
||||
)
|
||||
|
||||
// ReadRoleIDsFromContext extracts roleIDs from the metadata context and returns them as []string
|
||||
func ReadRoleIDsFromContext(ctx context.Context) (roleIDs []string, ok bool) {
|
||||
roleIDsJSON, ok := metadata.Get(ctx, middleware.RoleIDs)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
err := json.Unmarshal([]byte(roleIDsJSON), &roleIDs)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return roleIDs, true
|
||||
}
|
||||
Reference in New Issue
Block a user