| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package subconfigs
-
- import "fmt"
-
- // Config Consul客户端配置
- type ConsulConfig struct {
- BaseConfig
- Address string `yaml:"address"` // Consul服务器地址,如:"localhost:8500"
- Token string `yaml:"token"` // ACL token(可选)
- Scheme string `yaml:"scheme"` // "http" 或 "https"
- }
-
- func NewConsulConfig() *ConsulConfig {
- return &ConsulConfig{}
- }
-
- func (c *ConsulConfig) SetDefaults() {
- c.Address = "localhost:8500"
- 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() {
- Register("consul", &ConsulConfig{})
- }
|