44 lines
927 B
Go
44 lines
927 B
Go
package system
|
|
|
|
import "context"
|
|
|
|
type actorContextKey struct{}
|
|
|
|
type Actor struct {
|
|
UserID uint
|
|
AuthorityID uint
|
|
}
|
|
|
|
func NewActorContext(ctx context.Context, actor Actor) context.Context {
|
|
return context.WithValue(ctx, actorContextKey{}, actor)
|
|
}
|
|
|
|
func ActorFromContext(ctx context.Context) (Actor, bool) {
|
|
actor, ok := ctx.Value(actorContextKey{}).(Actor)
|
|
return actor, ok
|
|
}
|
|
|
|
type DataScope struct {
|
|
All bool
|
|
Scope int
|
|
UserID uint
|
|
AuthorityID uint
|
|
PrimaryDeptID uint
|
|
OwnerUserID uint
|
|
DepartmentIDs []uint
|
|
RequestID string
|
|
Method string
|
|
Path string
|
|
}
|
|
|
|
type dataScopeKey struct{}
|
|
|
|
func NewDataScopeContext(ctx context.Context, scope DataScope) context.Context {
|
|
return context.WithValue(ctx, dataScopeKey{}, scope)
|
|
}
|
|
|
|
func DataScopeFromContext(ctx context.Context) (DataScope, bool) {
|
|
scope, ok := ctx.Value(dataScopeKey{}).(DataScope)
|
|
return scope, ok
|
|
}
|