Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

consul_config.go 1001B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package subconfigs
  2. import (
  3. "fmt"
  4. "git.x2erp.com/qdy/go-base/config/core"
  5. )
  6. // Config Consul客户端配置
  7. type ConsulConfig struct {
  8. core.BaseConfig
  9. Address string `yaml:"address" desc:"Consul服务器地址,如:localhost:8500"`
  10. Token string `yaml:"token" desc:"ACL token(可选)"`
  11. Scheme string `yaml:"scheme" desc:"http 或 https"`
  12. }
  13. // consul.go
  14. func (c *ConsulConfig) Description() string {
  15. return "Consul客户端配置,用于服务发现和配置管理"
  16. }
  17. func NewConsulConfig() *ConsulConfig {
  18. return &ConsulConfig{}
  19. }
  20. func (c *ConsulConfig) SetDefaults() {
  21. c.Scheme = "http"
  22. }
  23. func (c *ConsulConfig) Load(data map[string]interface{}) error {
  24. return c.LoadFromYAML(data, c)
  25. }
  26. func (c *ConsulConfig) Validate() error {
  27. if c.Address == "" {
  28. return fmt.Errorf("consul address must be configured")
  29. }
  30. return nil
  31. }
  32. func (c *ConsulConfig) IsConfigured() bool {
  33. return c.Address != ""
  34. }
  35. // 自动注册
  36. func init() {
  37. core.Register("consul", &ConsulConfig{})
  38. }