添加获取RuntimeScope的方法
This commit is contained in:
parent
10cdd32e95
commit
ca7619af41
6
model.go
6
model.go
|
@ -1025,7 +1025,11 @@ func (m *Model) Import(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
//这里用background的context
|
||||
childCtx := context.WithValue(context.Background(), RuntimeScopeKey, &types.RuntimeScope{
|
||||
pCtx := m.db.Statement.Context
|
||||
if pCtx == nil {
|
||||
pCtx = context.Background()
|
||||
}
|
||||
childCtx := context.WithValue(pCtx, RuntimeScopeKey, &types.RuntimeScope{
|
||||
Domain: domainName,
|
||||
User: m.valueLookup(types.FieldUser, w, r),
|
||||
ModuleName: m.naming.ModuleName,
|
||||
|
|
10
rest.go
10
rest.go
|
@ -844,3 +844,13 @@ func OnAfterExport(cb AfterExport) {
|
|||
func OnAfterImport(cb AfterImport) {
|
||||
hookMgr.AfterImport(cb)
|
||||
}
|
||||
|
||||
// RuntimeScopeFromContext 从上下文中获取运行时作用域
|
||||
func RuntimeScopeFromContext(ctx context.Context) *types.RuntimeScope {
|
||||
if v := ctx.Value(RuntimeScopeKey); v != nil {
|
||||
if scope, ok := v.(*types.RuntimeScope); ok {
|
||||
return scope
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue