Documentation
¶
Index ¶
- Constants
- Variables
- func ConfigToMap(config interface{}) (map[string]string, error)
- func UpdateConfigFromMap(config interface{}, configMap map[string]string) error
- func ValidateConfigFromMap(config interface{}, configMap map[string]string) error
- type ConfigManager
- func (cm *ConfigManager) AssessOptionDiagnostic(key, value string) OptionDiagnosticAssessment
- func (cm *ConfigManager) ExportAllConfigs() map[string]string
- func (cm *ConfigManager) Get(name string) interface{}
- func (cm *ConfigManager) LoadFromDB(options map[string]string) error
- func (cm *ConfigManager) OptionDiagnosticFieldKind(key string) (kind string, ok bool)
- func (cm *ConfigManager) Register(name string, config interface{})
- func (cm *ConfigManager) SaveToDB(updateFunc func(key, value string) error) error
- type DiagnosticSchemaMapConfig
- type MapConfig
- type OptionDiagnosticAssessment
- type ValidatingMapConfig
Constants ¶
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 ¶
var ErrMapConfigValidationUnsupported = errors.New("MapConfig does not support side-effect-free validation")
ErrMapConfigValidationUnsupported reports that a MapConfig has no pure validation contract.
var GlobalConfig = NewConfigManager()
Functions ¶
func ConfigToMap ¶
ConfigToMap 将配置对象转换为map(导出函数)
func UpdateConfigFromMap ¶
UpdateConfigFromMap 从map更新配置对象(导出函数)
func ValidateConfigFromMap ¶
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) 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 注册一个配置模块
type DiagnosticSchemaMapConfig ¶
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 ¶
OptionDiagnosticAssessment contains only stable diagnostic codes. It never contains a configuration value or a parser error.