添加获取RuntimeScope的方法

This commit is contained in:
Yavolte 2025-07-30 13:57:08 +08:00
parent 10cdd32e95
commit ca7619af41
2 changed files with 15 additions and 1 deletions

View File

@ -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
View File

@ -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
}