ilk
This commit is contained in:
36
svc/internal/authz/context.go
Normal file
36
svc/internal/authz/context.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package authz
|
||||
|
||||
import "context"
|
||||
|
||||
type scopeKey string
|
||||
|
||||
const (
|
||||
CtxDeptCodesKey scopeKey = "authz.dept_codes"
|
||||
CtxPiyasaCodesKey scopeKey = "authz.piyasa_codes"
|
||||
)
|
||||
|
||||
func WithDeptCodes(ctx context.Context, codes []string) context.Context {
|
||||
return context.WithValue(ctx, CtxDeptCodesKey, codes)
|
||||
}
|
||||
|
||||
func WithPiyasaCodes(ctx context.Context, codes []string) context.Context {
|
||||
return context.WithValue(ctx, CtxPiyasaCodesKey, codes)
|
||||
}
|
||||
|
||||
func GetDeptCodesFromCtx(ctx context.Context) []string {
|
||||
if v := ctx.Value(CtxDeptCodesKey); v != nil {
|
||||
if codes, ok := v.([]string); ok {
|
||||
return codes
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetPiyasaCodesFromCtx(ctx context.Context) []string {
|
||||
if v := ctx.Value(CtxPiyasaCodesKey); v != nil {
|
||||
if codes, ok := v.([]string); ok {
|
||||
return codes
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user