Documentation
¶
Overview ¶
Package settings 提供设置接缝(ctx.settings):分层作用域 + 路径操作 + CAS + 密钥脱敏。
对齐上游:packages/settings/settings + settings-file
设计要点:
- SettingsScope 基于 pkg/scope 分层:host 层定义默认值,session 层可覆盖(nearest-wins);
- 更新通过 SettingsPathOp{set/unset} 表达,携带 expectedRevision 做 CAS 乐观锁;
- describe(redactSecrets:true) 对 secret 路径只输出 set/unset 操作位,value 全脱敏, 避免把密钥明文泄漏给模型或日志。
Index ¶
- func IsRevisionMismatch(err error) bool
- type DescribedSetting
- type ErrRevisionMismatch
- type Path
- type PathOp
- type SettingsNamespace
- type SettingsScope
- func (s *SettingsScope) ApplyHost(path Path, value any) error
- func (s *SettingsScope) Describe(redactSecrets bool) []DescribedSetting
- func (s *SettingsScope) Get(path Path) (json.RawMessage, bool)
- func (s *SettingsScope) Replace(expectedRevision uint64, values map[Path]any) error
- func (s *SettingsScope) Revision() uint64
- func (s *SettingsScope) Update(expectedRevision uint64, ops map[Path]PathOp) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DescribedSetting ¶
type DescribedSetting struct {
Path Path `json:"path"`
Op string `json:"op"` // "set" / "unset" / "default"
Value any `json:"value,omitempty"`
Secret bool `json:"secret,omitempty"`
}
DescribedSetting 是 describe 输出的单条设置。
type ErrRevisionMismatch ¶
ErrRevisionMismatch 是 CAS 修订号冲突错误。
type PathOp ¶
type PathOp struct {
// Set 非 nil 表示设置该路径为该值;否则表示 unset。
Set *json.RawMessage `json:"set,omitempty"`
}
PathOp 是单个设置路径操作。
type SettingsNamespace ¶
type SettingsNamespace struct {
// Name 命名空间名。
Name string
// SecretPaths 属于密钥的路径集合(describe 时脱敏)。
SecretPaths map[Path]struct{}
}
SettingsNamespace 描述一个设置命名空间(含哪些路径属于 secret)。
func (*SettingsNamespace) IsSecret ¶
func (ns *SettingsNamespace) IsSecret(p Path) bool
IsSecret 判断路径是否密钥。
func (*SettingsNamespace) MarkSecret ¶
func (ns *SettingsNamespace) MarkSecret(p Path)
MarkSecret 将某路径标记为密钥。
type SettingsScope ¶
type SettingsScope struct {
// contains filtered or unexported fields
}
SettingsScope 是设置的作用域视图(host 层 + session 层)。
func NewSettingsScope ¶
func NewSettingsScope(ns *SettingsNamespace) *SettingsScope
NewSettingsScope 创建设置作用域(host 层先建立)。
func (*SettingsScope) ApplyHost ¶
func (s *SettingsScope) ApplyHost(path Path, value any) error
ApplyHost 设置 host 层默认值(expectedRevision=0 表示初始或强制)。
func (*SettingsScope) Describe ¶
func (s *SettingsScope) Describe(redactSecrets bool) []DescribedSetting
Describe 输出当前设置描述。redactSecrets=true 时 secret 路径只给操作位不给明文。
func (*SettingsScope) Get ¶
func (s *SettingsScope) Get(path Path) (json.RawMessage, bool)
Get 按 nearest-wins 读取路径值(返回原始 JSON 字节)。
func (*SettingsScope) Replace ¶
func (s *SettingsScope) Replace(expectedRevision uint64, values map[Path]any) error
Replace 整体替换 session 层设置(CAS)。
func (*SettingsScope) Revision ¶
func (s *SettingsScope) Revision() uint64
Revision 返回当前修订号(每次 update/replace 后递增)。
Click to show internal directories.
Click to hide internal directories.