settingssnap

package
v0.0.1-beta.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package settingssnap 是 settings 全量内存快照的唯一事实源(根因重开): Service 与 MailWorker 同源共享单个 *Snapshot(单指针,无双快照分叉)。 叶子包:仅依赖 domain + logx + 标准库,不 import internal/repository(防环—— SettingsLoader 窄接口由 repos/fakeStore 结构性满足)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SettingsLoader

type SettingsLoader interface {
	GetAllSettings(ctx context.Context) ([]*domain.Setting, error)
}

SettingsLoader 窄接口:快照唯一上游。repos 与测试 fake 均已满足。

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot settings 全量内存快照(默认值 + DB 覆盖):公开读路径零 DB 直读; 仅管理面 UpdateSetting / NOTIFY dispatcher 低频重载(无锁,atomic 指针交换)。

func New

func New(store SettingsLoader, log *logx.Logger) *Snapshot

New 构造快照(不加载;调用方 Load 首载,失败 Warn 语义由调用方保持)。

func (*Snapshot) Int

func (s *Snapshot) Int(key string) int64

Int 快照数值读取:缺失/解析失败 → 0(UpdateSetting 已做类型化校验, 此处仅防御性兜底;解析失败按 0 = 不送/不限语义)。

func (*Snapshot) Load

func (s *Snapshot) Load(ctx context.Context) error

Load 首载(New 后调用一次)。

func (*Snapshot) Log

func (s *Snapshot) Log() *logx.Logger

Log 日志面(MailWorker 构造前已存在,透出只读)。

func (*Snapshot) MailConfig

func (s *Snapshot) MailConfig() (host string, port int, username, password, fromAddr, tlsPolicy string, ok bool)

MailConfig 邮件通道配置(7 返回;语义与原 service.mailConfig 逐行一致)。 nil 接收者 → !ok(未配置降级,与旧空快照语义一致)。

func (*Snapshot) Reload

func (s *Snapshot) Reload(ctx context.Context) error

Reload 全量重载(UpdateSetting / dispatcher Apply-FullRefresh 共用)。

func (*Snapshot) Value

func (s *Snapshot) Value(key string) string

Value 快照查值:缺失(含快照未初始化)返回空串。nil 接收者安全 (字面量 Service 测试绕过 New——读路径零值,与旧原子指针 nil 语义一致)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL