MCPcopy Create free account
hub / github.com/astercloud/aster / Namespace

Method Namespace

pkg/memory/scope.go:59–86  ·  view source on GitHub ↗

Namespace 根据 Scope 生成 namespace 字符串。 规则: - ProjectID 不为空时: 追加 "projects/ " - ResourceType & ResourceID 不为空时: 追加 "resources/ / " - Shared=false => 不加前导 "/", 交由 BaseNamespace 叠加 (用户级/租户级记忆) - Shared=true => 加前导 "/", 作为全局/共享记忆 示例: Scope{UserID:"alice", ProjectID:"demo", Shared:f

()

Source from the content-addressed store, hash-verified

57// Scope{ProjectID:"demo", ResourceType:"article", ResourceID:"abc", Shared:true}.Namespace()
58// -> "/projects/demo/resources/article/abc"
59func (s Scope) Namespace() string {
60 var parts []string
61
62 if strings.TrimSpace(s.ProjectID) != "" {
63 parts = append(parts, "projects", strings.TrimSpace(s.ProjectID))
64 }
65
66 if strings.TrimSpace(s.ResourceType) != "" && strings.TrimSpace(s.ResourceID) != "" {
67 parts = append(parts,
68 "resources",
69 strings.TrimSpace(s.ResourceType),
70 strings.TrimSpace(s.ResourceID),
71 )
72 }
73
74 if len(parts) == 0 {
75 // 未绑定项目或资源, 返回空字符串
76 return ""
77 }
78
79 ns := filepath.ToSlash(filepath.Join(parts...))
80 if s.Shared {
81 // 共享/全局命名空间, 使用前导 "/" 阻止 BaseNamespace 叠加
82 return "/" + ns
83 }
84 // 用户级命名空间, 不加 "/", 由 BaseNamespace 叠加
85 return ns
86}

Callers 3

ExecuteMethod · 0.95
ExecuteMethod · 0.95
ExecuteMethod · 0.95

Calls 1

JoinMethod · 0.45

Tested by

no test coverage detected