| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package subconfigs
-
- import (
- "fmt"
-
- "git.x2erp.com/qdy/go-base/config/core"
- )
-
- // Config Consul客户端配置
- type ConsulConfig struct {
- core.BaseConfig
- Address string `yaml:"address" desc:"Consul服务器地址,如:localhost:8500"`
- Token string `yaml:"token" desc:"ACL token(可选)"`
- Scheme string `yaml:"scheme" desc:"http 或 https"`
- }
-
- // consul.go
- func (c *ConsulConfig) Description() string {
- return "Consul客户端配置,用于服务发现和配置管理"
- }
-
- func NewConsulConfig() *ConsulConfig {
- return &ConsulConfig{}
- }
-
- func (c *ConsulConfig) SetDefaults() {
- c.Scheme = "http"
- }
-
- func (c *ConsulConfig) Load(data map[string]interface{}) error {
- return c.LoadFromYAML(data, c)
- }
-
- func (c *ConsulConfig) Validate() error {
- if c.Address == "" {
- return fmt.Errorf("consul address must be configured")
- }
- return nil
- }
-
- func (c *ConsulConfig) IsConfigured() bool {
- return c.Address != ""
- }
-
- // 自动注册
- func init() {
- core.Register("consul", &ConsulConfig{})
- }
|