package subconfigs import "fmt" // MicroConfig Go Micro微服务配置 type MicroConfig struct { BaseConfig RegistryAddress string `yaml:"registry_address"` RegistryType string `yaml:"registry_type"` RegistryTimeout int `yaml:"registry_timeout"` LBStrategy string `yaml:"lb_strategy"` LBCacheTTL int `yaml:"lb_cache_ttl"` LBRetries int `yaml:"lb_retries"` ClientTimeout int `yaml:"client_timeout"` ClientPoolSize int `yaml:"client_pool_size"` MaxRetries int `yaml:"max_retries"` CircuitEnabled bool `yaml:"circuit_enabled"` CircuitTimeout int `yaml:"circuit_timeout"` ErrorThreshold int `yaml:"error_threshold"` SleepWindow int `yaml:"sleep_window"` HealthPath string `yaml:"health_path"` HealthInterval int `yaml:"health_interval"` HealthTimeout int `yaml:"health_timeout"` LogLevel string `yaml:"log_level"` EnableDebug bool `yaml:"enable_debug"` MetricsEnabled bool `yaml:"metrics_enabled"` MetricsAddress string `yaml:"metrics_address"` TracerEnabled bool `yaml:"tracer_enabled"` TracerAddress string `yaml:"tracer_address"` } func NewMicroConfig() *MicroConfig { return &MicroConfig{} } func (c *MicroConfig) SetDefaults() { //c.RegistryAddress = "localhost:8500" c.RegistryType = "consul" c.RegistryTimeout = 10 c.LBStrategy = "roundrobin" c.LBCacheTTL = 30 c.LBRetries = 3 c.ClientTimeout = 30 c.ClientPoolSize = 100 c.MaxRetries = 3 c.CircuitEnabled = true c.CircuitTimeout = 60 c.ErrorThreshold = 5 c.SleepWindow = 5000 c.HealthPath = "/health" c.HealthInterval = 10 c.HealthTimeout = 5 c.LogLevel = "info" c.EnableDebug = false c.MetricsEnabled = true c.MetricsAddress = ":9090" } func (c *MicroConfig) Load(data map[string]interface{}) error { return c.LoadFromYAML(data, c) } func (c *MicroConfig) Validate() error { if c.RegistryAddress == "" { return fmt.Errorf("registry address is required") } return nil } func (c *MicroConfig) IsConfigured() bool { return c.RegistryAddress != "" } // 自动注册 func init() { Register("micro", &MicroConfig{}) }