config

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConfigManagerNotInitialized = &ConfigError{
	Code:    "CONFIG_MANAGER_NOT_INITIALIZED",
	Message: "配置管理器未初始化",
}

ErrConfigManagerNotInitialized 配置管理器未初始化错误

Functions

func GetConfigBool

func GetConfigBool(key string) (bool, error)

GetConfigBool 获取布尔配置值(全局函数)

func GetConfigBoolWithEnvFallback

func GetConfigBoolWithEnvFallback(configKey, envKey string) (bool, error)

GetConfigBoolWithEnvFallback 获取布尔配置值(环境变量优先,全局函数)

func GetConfigFloat64

func GetConfigFloat64(key string) (float64, error)

GetConfigFloat64 获取浮点数配置值(全局函数)

func GetConfigInt

func GetConfigInt(key string) (int, error)

GetConfigInt 获取整数配置值(全局函数)

func GetConfigInt64

func GetConfigInt64(key string) (int64, error)

GetConfigInt64 获取64位整数配置值(全局函数)

func GetConfigIntWithEnvFallback

func GetConfigIntWithEnvFallback(configKey, envKey string) (int, error)

GetConfigIntWithEnvFallback 获取整数配置值(环境变量优先,全局函数)

func GetConfigValue

func GetConfigValue(key string) (string, error)

GetConfigValue 获取配置值(全局函数)

func GetConfigWithEnvFallback

func GetConfigWithEnvFallback(configKey, envKey string) (string, error)

GetConfigWithEnvFallback 获取配置值(环境变量优先,全局函数)

func SetConfig

func SetConfig(key, value string) error

SetConfig 设置配置值(全局函数)

func SetConfigWithType

func SetConfigWithType(key, value, configType string) error

SetConfigWithType 设置配置值(指定类型,全局函数)

func SetGlobalConfigManager

func SetGlobalConfigManager(cm *ConfigManager)

SetGlobalConfigManager 设置全局配置管理器

Types

type ConfigError

type ConfigError struct {
	Code    string
	Message string
}

ConfigError 配置错误

func (*ConfigError) Error

func (e *ConfigError) Error() string

type ConfigGroup

type ConfigGroup string

ConfigGroup 配置分组

const (
	GroupDatabase    ConfigGroup = "database"
	GroupServer      ConfigGroup = "server"
	GroupSecurity    ConfigGroup = "security"
	GroupSearch      ConfigGroup = "search"
	GroupTelegram    ConfigGroup = "telegram"
	GroupCache       ConfigGroup = "cache"
	GroupMeilisearch ConfigGroup = "meilisearch"
	GroupSEO         ConfigGroup = "seo"
	GroupAutoProcess ConfigGroup = "auto_process"
	GroupOther       ConfigGroup = "other"
)

type ConfigItem

type ConfigItem struct {
	Key         string    `json:"key"`
	Value       string    `json:"value"`
	Type        string    `json:"type"`
	UpdatedAt   time.Time `json:"updated_at"`
	Group       string    `json:"group"`        // 配置分组
	Category    string    `json:"category"`     // 配置分类
	IsSensitive bool      `json:"is_sensitive"` // 是否是敏感信息
}

ConfigItem 配置项结构

func GetConfig

func GetConfig(key string) (*ConfigItem, error)

GetConfig 获取配置值(全局函数)

type ConfigManager

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

ConfigManager 统一配置管理器

func GetGlobalConfigManager

func GetGlobalConfigManager() *ConfigManager

GetGlobalConfigManager 获取全局配置管理器

func NewConfigManager

func NewConfigManager(repoManager *repo.RepositoryManager) *ConfigManager

NewConfigManager 创建配置管理器

func (*ConfigManager) AddConfigWatcher

func (cm *ConfigManager) AddConfigWatcher() chan string

AddConfigWatcher 添加配置变更监听器

func (*ConfigManager) DeleteConfig

func (cm *ConfigManager) DeleteConfig(key string) error

DeleteConfig 删除配置

func (*ConfigManager) GetConfig

func (cm *ConfigManager) GetConfig(key string) (*ConfigItem, error)

GetConfig 获取配置项

func (*ConfigManager) GetConfigAsJSON

func (cm *ConfigManager) GetConfigAsJSON() ([]byte, error)

GetConfigAsJSON 获取配置为JSON格式

func (*ConfigManager) GetConfigBool

func (cm *ConfigManager) GetConfigBool(key string) (bool, error)

GetConfigBool 获取布尔值配置

func (*ConfigManager) GetConfigBoolWithEnvFallback

func (cm *ConfigManager) GetConfigBoolWithEnvFallback(configKey, envKey string) (bool, error)

GetConfigBoolWithEnvFallback 获取布尔配置,环境变量优先

func (*ConfigManager) GetConfigByCategory

func (cm *ConfigManager) GetConfigByCategory(category string) (map[string]*ConfigItem, error)

GetConfigByCategory 按分类获取配置

func (*ConfigManager) GetConfigByGroup

func (cm *ConfigManager) GetConfigByGroup(group ConfigGroup) (map[string]*ConfigItem, error)

GetConfigByGroup 按分组获取配置

func (*ConfigManager) GetConfigFloat64

func (cm *ConfigManager) GetConfigFloat64(key string) (float64, error)

GetConfigFloat64 获取浮点数配置

func (*ConfigManager) GetConfigInt

func (cm *ConfigManager) GetConfigInt(key string) (int, error)

GetConfigInt 获取整数值配置

func (*ConfigManager) GetConfigInt64

func (cm *ConfigManager) GetConfigInt64(key string) (int64, error)

GetConfigInt64 获取64位整数值配置

func (*ConfigManager) GetConfigIntWithEnvFallback

func (cm *ConfigManager) GetConfigIntWithEnvFallback(configKey, envKey string) (int, error)

GetConfigIntWithEnvFallback 获取整数配置,环境变量优先

func (*ConfigManager) GetConfigStatistics

func (cm *ConfigManager) GetConfigStatistics() map[string]interface{}

GetConfigStatistics 获取配置统计信息

func (*ConfigManager) GetConfigValue

func (cm *ConfigManager) GetConfigValue(key string) (string, error)

GetConfigValue 获取配置值

func (*ConfigManager) GetConfigWithEnvFallback

func (cm *ConfigManager) GetConfigWithEnvFallback(configKey, envKey string) (string, error)

GetConfigWithEnvFallback 获取配置,环境变量优先

func (*ConfigManager) GetConfigWithMask

func (cm *ConfigManager) GetConfigWithMask(key string) (*ConfigItem, error)

GetConfigWithMask 获取配置值(敏感配置会被遮蔽)

func (*ConfigManager) GetEnvironmentConfig

func (cm *ConfigManager) GetEnvironmentConfig(key string) (string, bool)

GetEnvironmentConfig 从环境变量获取配置

func (*ConfigManager) GetSensitiveConfigKeys

func (cm *ConfigManager) GetSensitiveConfigKeys() []string

GetSensitiveConfigKeys 获取所有敏感配置键

func (*ConfigManager) LoadAllConfigs

func (cm *ConfigManager) LoadAllConfigs() error

LoadAllConfigs 加载所有配置到缓存

func (*ConfigManager) RefreshConfigCache

func (cm *ConfigManager) RefreshConfigCache() error

RefreshConfigCache 刷新配置缓存

func (*ConfigManager) SetConfig

func (cm *ConfigManager) SetConfig(key, value string) error

SetConfig 设置配置值

func (*ConfigManager) SetConfigWithType

func (cm *ConfigManager) SetConfigWithType(key, value, configType string) error

SetConfigWithType 设置配置值(指定类型)

func (*ConfigManager) SyncWithRepository

func (cm *ConfigManager) SyncWithRepository(repoManager *repo.RepositoryManager)

SyncWithRepository 同步配置管理器与Repository的缓存

func (*ConfigManager) UpdateRepositoryCache

func (cm *ConfigManager) UpdateRepositoryCache(repoManager *repo.RepositoryManager)

UpdateRepositoryCache 当配置管理器更新配置时,通知Repository层同步

Jump to

Keyboard shortcuts

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