Нема описа
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 843B

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