2014-07-25 23:03:17 +02:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2015-01-07 02:11:29 +01:00
|
|
|
consulapi "github.com/hashicorp/consul/api"
|
2014-07-25 23:03:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Datacenter string `mapstructure:"datacenter"`
|
|
|
|
Address string `mapstructure:"address"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client() returns a new client for accessing digital
|
|
|
|
// ocean.
|
|
|
|
//
|
|
|
|
func (c *Config) Client() (*consulapi.Client, error) {
|
|
|
|
config := consulapi.DefaultConfig()
|
|
|
|
if c.Datacenter != "" {
|
|
|
|
config.Datacenter = c.Datacenter
|
|
|
|
}
|
|
|
|
if c.Address != "" {
|
|
|
|
config.Address = c.Address
|
|
|
|
}
|
|
|
|
client, err := consulapi.NewClient(config)
|
|
|
|
|
2014-07-26 04:14:48 +02:00
|
|
|
log.Printf("[INFO] Consul Client configured with address: '%s', datacenter: '%s'",
|
|
|
|
config.Address, config.Datacenter)
|
2014-07-25 23:03:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return client, nil
|
|
|
|
}
|