config

package
v0.2.0-beta.7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const OptionDiagnosticMaxKeyChars = 256

OptionDiagnosticMaxKeyChars is the largest database option key diagnostics will classify. The database reader uses the same character limit so an untrusted key is bounded before it enters Go.

Variables

View Source
var ErrMapConfigValidationUnsupported = errors.New("MapConfig does not support side-effect-free validation")

ErrMapConfigValidationUnsupported reports that a MapConfig has no pure validation contract.

View Source
var GlobalConfig = NewConfigManager()

Functions

func ConfigToMap

func ConfigToMap(config interface{}) (map[string]string, error)

ConfigToMap 将配置对象转换为map(导出函数)

func UpdateConfigFromMap

func UpdateConfigFromMap(config interface{}, configMap map[string]string) error

UpdateConfigFromMap 从map更新配置对象(导出函数)

func ValidateConfigFromMap

func ValidateConfigFromMap(config interface{}, configMap map[string]string) error

ValidateConfigFromMap validates an update without changing config.

Types

type ConfigManager

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

ConfigManager 统一管理所有配置

func NewConfigManager

func NewConfigManager() *ConfigManager

func (*ConfigManager) AssessOptionDiagnostic

func (cm *ConfigManager) AssessOptionDiagnostic(key, value string) OptionDiagnosticAssessment

AssessOptionDiagnostic evaluates a registered configuration key without reading or changing the registered value. Reflection-based configurations are parsed into a zero-value field. A managed map configuration is inspected only through DiagnosticSchema, whose zero value carries field names and types but no configured value; its own validator is never invoked here, because that would read a live runtime generation. A managed configuration without that schema stays indeterminate rather than being guessed at.

func (*ConfigManager) ExportAllConfigs

func (cm *ConfigManager) ExportAllConfigs() map[string]string

ExportAllConfigs 导出所有已注册的配置为扁平结构

func (*ConfigManager) Get

func (cm *ConfigManager) Get(name string) interface{}

Get 获取指定配置模块

func (*ConfigManager) LoadFromDB

func (cm *ConfigManager) LoadFromDB(options map[string]string) error

LoadFromDB 从数据库加载配置

func (*ConfigManager) OptionDiagnosticFieldKind

func (cm *ConfigManager) OptionDiagnosticFieldKind(key string) (kind string, ok bool)

OptionDiagnosticFieldKind reports the stable storage kind class of a registered configuration field: "boolean", "integer", "unsigned_integer", "finite_number", "string", "json", or "unsupported". ok is false for keys that are not registered fields. The lookup walks the same schema-only path as AssessOptionDiagnostic: it never reads a configured value and never invokes a configuration validator.

func (*ConfigManager) Register

func (cm *ConfigManager) Register(name string, config interface{})

Register 注册一个配置模块

func (*ConfigManager) SaveToDB

func (cm *ConfigManager) SaveToDB(updateFunc func(key, value string) error) error

SaveToDB 将配置保存到数据库

type DiagnosticSchemaMapConfig

type DiagnosticSchemaMapConfig interface {
	MapConfig
	DiagnosticSchema() any
}

DiagnosticSchemaMapConfig lets a MapConfig expose its field schema to diagnostics. Implementations must return a fresh zero value of the schema struct, never a live runtime generation, so a caller can inspect field names and types without observing configured values.

type MapConfig

type MapConfig interface {
	ExportConfigMap() (map[string]string, error)
	UpdateConfigMap(map[string]string) error
}

MapConfig lets a module own its synchronization and validation instead of exposing mutable fields to the generic reflection-based loader/exporter.

type OptionDiagnosticAssessment

type OptionDiagnosticAssessment struct {
	KeyClass   string
	Validation string
}

OptionDiagnosticAssessment contains only stable diagnostic codes. It never contains a configuration value or a parser error.

type ValidatingMapConfig

type ValidatingMapConfig interface {
	MapConfig
	ValidateConfigMap(map[string]string) error
}

ValidatingMapConfig extends MapConfig with side-effect-free validation. Implementations must not publish the candidate configuration.

Jump to

Keyboard shortcuts

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