config

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNonFatal

func IsNonFatal(err error) bool

func Load

func Load() (*Config, *ExternalConfig, error)

Load 加载主程序配置,支持优先级:环境变量 > 配置文件 > 默认值。

Types

type AliyunConfig

type AliyunConfig struct {
	AccessKeyID     string `env:"ALIYUN_ACCESS_KEY_ID" default:""`
	AccessKeySecret string `env:"ALIYUN_ACCESS_KEY_SECRET" default:""`
}

AliyunConfig 阿里云配置(来自环境变量)

type Config

type Config struct {
	Server       ServerConfig       `mapstructure:"server"`
	Log          LogConfig          `mapstructure:"log"`
	JWT          JWTConfig          `mapstructure:"jwt"`
	Redis        RedisConfig        `mapstructure:"redis"`
	MySQL        MySQLConfig        `mapstructure:"mysql"`
	Tree         TreeConfig         `mapstructure:"tree"`
	K8s          K8sConfig          `mapstructure:"k8s"`
	Prometheus   PrometheusConfig   `mapstructure:"prometheus"`
	Mock         MockConfig         `mapstructure:"mock"`
	Notification NotificationConfig `mapstructure:"notification"`
	Webhook      WebhookConfig      `mapstructure:"webhook"`
}

func (*Config) Validate

func (c *Config) Validate() error

type EmailConfig

type EmailConfig struct {
	Enabled       bool   `mapstructure:"enabled" env:"NOTIFICATION_EMAIL_ENABLED" default:"false"`
	SMTPHost      string `mapstructure:"smtp_host" env:"NOTIFICATION_EMAIL_SMTP_HOST" default:"smtp.gmail.com"`
	SMTPPort      int    `mapstructure:"smtp_port" env:"NOTIFICATION_EMAIL_SMTP_PORT" default:"587"`
	Username      string `mapstructure:"username" env:"NOTIFICATION_EMAIL_USERNAME" default:""`
	Password      string `mapstructure:"password" env:"NOTIFICATION_EMAIL_PASSWORD" default:""`
	FromName      string `mapstructure:"from_name" env:"NOTIFICATION_EMAIL_FROM_NAME" default:"AI-CloudOps"`
	MaxRetries    int    `mapstructure:"max_retries" env:"NOTIFICATION_EMAIL_MAX_RETRIES" default:"3"`
	RetryInterval string `mapstructure:"retry_interval" env:"NOTIFICATION_EMAIL_RETRY_INTERVAL" default:"5m"`
	Timeout       string `mapstructure:"timeout" env:"NOTIFICATION_EMAIL_TIMEOUT" default:"30s"`
	UseTLS        bool   `mapstructure:"use_tls" env:"NOTIFICATION_EMAIL_USE_TLS" default:"true"`
}

func (*EmailConfig) GetChannelName

func (c *EmailConfig) GetChannelName() string

func (*EmailConfig) GetFromName

func (c *EmailConfig) GetFromName() string

func (*EmailConfig) GetMaxRetries

func (c *EmailConfig) GetMaxRetries() int

func (*EmailConfig) GetPassword

func (c *EmailConfig) GetPassword() string

func (*EmailConfig) GetRetryInterval

func (c *EmailConfig) GetRetryInterval() time.Duration

func (*EmailConfig) GetSMTPHost

func (c *EmailConfig) GetSMTPHost() string

func (*EmailConfig) GetSMTPPort

func (c *EmailConfig) GetSMTPPort() int

func (*EmailConfig) GetTimeout

func (c *EmailConfig) GetTimeout() time.Duration

func (*EmailConfig) GetUseTLS

func (c *EmailConfig) GetUseTLS() bool

func (*EmailConfig) GetUsername

func (c *EmailConfig) GetUsername() string

func (*EmailConfig) IsEnabled

func (c *EmailConfig) IsEnabled() bool

func (*EmailConfig) Validate

func (c *EmailConfig) Validate() error

type ExternalConfig

type ExternalConfig struct {
	LLM    LLMConfig    `mapstructure:"llm"`
	Aliyun AliyunConfig `mapstructure:"aliyun"`
	Tavily TavilyConfig `mapstructure:"tavily"`
}

ExternalConfig 外部服务配置(仅来自环境变量)

type FeishuConfig

type FeishuConfig struct {
	Enabled              bool   `mapstructure:"enabled" env:"NOTIFICATION_FEISHU_ENABLED" default:"false"`
	AppID                string `mapstructure:"app_id" env:"NOTIFICATION_FEISHU_APP_ID" default:""`
	AppSecret            string `mapstructure:"app_secret" env:"NOTIFICATION_FEISHU_APP_SECRET" default:""`
	WebhookURL           string `mapstructure:"webhook_url" env:"NOTIFICATION_FEISHU_WEBHOOK_URL" default:"https://open.feishu.cn/open-apis/bot/v2/hook/"`
	PrivateMessageAPI    string `` /* 138-byte string literal not displayed */
	TenantAccessTokenAPI string `` /* 168-byte string literal not displayed */
	MaxRetries           int    `mapstructure:"max_retries" env:"NOTIFICATION_FEISHU_MAX_RETRIES" default:"3"`
	RetryInterval        string `mapstructure:"retry_interval" env:"NOTIFICATION_FEISHU_RETRY_INTERVAL" default:"5m"`
	Timeout              string `mapstructure:"timeout" env:"NOTIFICATION_FEISHU_TIMEOUT" default:"10s"`
}

func (*FeishuConfig) GetAppID

func (c *FeishuConfig) GetAppID() string

func (*FeishuConfig) GetAppSecret

func (c *FeishuConfig) GetAppSecret() string

func (*FeishuConfig) GetChannelName

func (c *FeishuConfig) GetChannelName() string

func (*FeishuConfig) GetMaxRetries

func (c *FeishuConfig) GetMaxRetries() int

func (*FeishuConfig) GetPrivateMessageAPI

func (c *FeishuConfig) GetPrivateMessageAPI() string

func (*FeishuConfig) GetRetryInterval

func (c *FeishuConfig) GetRetryInterval() time.Duration

func (*FeishuConfig) GetTenantAccessTokenAPI

func (c *FeishuConfig) GetTenantAccessTokenAPI() string

func (*FeishuConfig) GetTimeout

func (c *FeishuConfig) GetTimeout() time.Duration

func (*FeishuConfig) GetWebhookURL

func (c *FeishuConfig) GetWebhookURL() string

func (*FeishuConfig) IsEnabled

func (c *FeishuConfig) IsEnabled() bool

func (*FeishuConfig) Validate

func (c *FeishuConfig) Validate() error

type ImFeishuConfig

type ImFeishuConfig struct {
	GroupMessageAPI       string `` /* 132-byte string literal not displayed */
	RequestTimeoutSeconds int    `mapstructure:"request_timeout_seconds" env:"WEBHOOK_IM_FEISHU_REQUEST_TIMEOUT_SECONDS" default:"10"`
	PrivateRobotAppID     string `mapstructure:"private_robot_app_id" env:"WEBHOOK_IM_FEISHU_PRIVATE_ROBOT_APP_ID" default:""`
	PrivateRobotAppSecret string `mapstructure:"private_robot_app_secret" env:"WEBHOOK_IM_FEISHU_PRIVATE_ROBOT_APP_SECRET" default:""`
	TenantAccessTokenAPI  string `` /* 166-byte string literal not displayed */
}

type JWTConfig

type JWTConfig struct {
	Key1       string `mapstructure:"key1" env:"JWT_KEY1" default:"ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0l"`
	Key2       string `mapstructure:"key2" env:"JWT_KEY2" default:"ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0z"`
	Issuer     string `mapstructure:"issuer" env:"JWT_ISSUER" default:"K5mBPBYNQeNWEBvCTE5msog3KSGTdhmx"`
	Expiration int64  `mapstructure:"expiration" env:"JWT_EXPIRATION" default:"3600"`
}

JWTConfig JWT配置

type K8sConfig

type K8sConfig struct {
	RefreshCron string `mapstructure:"refresh_cron" env:"K8S_REFRESH_CRON" default:"@every 300s"`
}

K8sConfig Kubernetes配置

type LLMConfig

type LLMConfig struct {
	APIKey  string `env:"LLM_API_KEY" default:""`
	BaseURL string `env:"LLM_BASE_URL" default:""`
}

LLMConfig LLM配置(来自环境变量)

type LogConfig

type LogConfig struct {
	Dir   string `mapstructure:"dir" env:"LOG_DIR" default:"./logs"`
	Level string `mapstructure:"level" env:"LOG_LEVEL" default:"debug"`
}

type MockConfig

type MockConfig struct {
	Enabled bool `mapstructure:"enabled" env:"MOCK_ENABLED" default:"true"`
}

MockConfig Mock配置

type MySQLConfig

type MySQLConfig struct {
	Addr string `` /* 126-byte string literal not displayed */
}

MySQLConfig MySQL配置

type NonFatalError

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

NonFatalError 用于标记“可继续运行”的告警类错误(例如配置文件不存在)。

func (NonFatalError) Error

func (e NonFatalError) Error() string

func (NonFatalError) Unwrap

func (e NonFatalError) Unwrap() error

type NotificationConfig

type NotificationConfig struct {
	Email  *EmailConfig  `mapstructure:"email"`
	Feishu *FeishuConfig `mapstructure:"feishu"`
}

func (*NotificationConfig) GetEmail

func (c *NotificationConfig) GetEmail() *EmailConfig

func (*NotificationConfig) GetFeishu

func (c *NotificationConfig) GetFeishu() *FeishuConfig

type PrometheusConfig

type PrometheusConfig struct {
	RefreshCron         string `mapstructure:"refresh_cron" env:"PROMETHEUS_REFRESH_CRON" default:"@every 15s"`
	EnableAlert         int    `mapstructure:"enable_alert" env:"PROMETHEUS_ENABLE_ALERT" default:"0"`
	EnableRecord        int    `mapstructure:"enable_record" env:"PROMETHEUS_ENABLE_RECORD" default:"0"`
	AlertWebhookAddr    string `mapstructure:"alert_webhook_addr" env:"PROMETHEUS_ALERT_WEBHOOK_ADDR" default:"http://localhost:8889/api/v1/alerts/receive"`
	AlertWebhookFileDir string `mapstructure:"alert_webhook_file_dir" env:"PROMETHEUS_ALERT_WEBHOOK_FILE_DIR" default:"/tmp/webhook_files"`
	HttpSdAPI           string `mapstructure:"httpSdAPI" env:"PROMETHEUS_HTTP_SD_API" default:"http://localhost:8888/api/not_auth/getTreeNodeBindIps"`
}

PrometheusConfig Prometheus配置

type RedisConfig

type RedisConfig struct {
	Addr     string `mapstructure:"addr" env:"REDIS_ADDR" default:"localhost:6379"`
	Password string `mapstructure:"password" env:"REDIS_PASSWORD" default:""`
}

RedisConfig Redis配置

type ServerConfig

type ServerConfig struct {
	Port string `mapstructure:"port" env:"SERVER_PORT" default:"8889"`
}

type TavilyConfig

type TavilyConfig struct {
	APIKey string `env:"TAVILY_API_KEY" default:""`
}

TavilyConfig Tavily配置(来自环境变量)

type TreeConfig

type TreeConfig struct {
	CheckStatusCron       string `mapstructure:"check_status_cron" env:"TREE_CHECK_STATUS_CRON" default:"@every 300s"`
	PasswordEncryptionKey string `mapstructure:"password_encryption_key" env:"TREE_PASSWORD_ENCRYPTION_KEY" default:"ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0l"`
}

type WebhookConfig

type WebhookConfig struct {
	Port                          string         `mapstructure:"port" env:"WEBHOOK_PORT" default:"8888"`
	FixedWorkers                  int            `mapstructure:"fixed_workers" env:"WEBHOOK_FIXED_WORKERS" default:"10"`
	FrontDomain                   string         `mapstructure:"front_domain" env:"WEBHOOK_FRONT_DOMAIN" default:"http://localhost:3000"`
	BackendDomain                 string         `mapstructure:"backend_domain" env:"WEBHOOK_BACKEND_DOMAIN" default:"http://localhost:8889"`
	DefaultUpgradeMinutes         int            `mapstructure:"default_upgrade_minutes" env:"WEBHOOK_DEFAULT_UPGRADE_MINUTES" default:"60"`
	AlertManagerAPI               string         `mapstructure:"alert_manager_api" env:"WEBHOOK_ALERT_MANAGER_API" default:"http://localhost:9093"`
	CommonMapRenewIntervalSeconds int            `mapstructure:"common_map_renew_interval_seconds" env:"WEBHOOK_COMMON_MAP_RENEW_INTERVAL_SECONDS" default:"300"`
	ImFeishu                      ImFeishuConfig `mapstructure:"im_feishu"`
}

WebhookConfig Webhook配置(用于webhook子系统)

func LoadWebhook

func LoadWebhook() (*WebhookConfig, error)

LoadWebhook 加载 Webhook 子系统配置,支持优先级:环境变量 > 配置文件 > 默认值。

Jump to

Keyboard shortcuts

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