-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Etcd Client is a little tricker because it requires a config file. Later when we unify all the clients we will use individual functions just like etcd.
- Loading branch information
Ryan Hallisey
committed
Jun 22, 2017
1 parent
e1a092b
commit 9b96a73
Showing
3 changed files
with
50 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package clients | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
logging "github.com/op/go-logging" | ||
|
||
"github.com/coreos/etcd/client" | ||
) | ||
|
||
type EtcdConfig struct { | ||
EtcdHost string `yaml:"etcd_host"` | ||
EtcdPort string `yaml:"etcd_port"` | ||
} | ||
|
||
func Etcd(config EtcdConfig, log *logging.Logger) (client.Client, error) { | ||
// TODO: Config validation | ||
endpoints := []string{etcdEndpoint(config.EtcdHost, config.EtcdPort)} | ||
|
||
log.Info("== ETCD CX ==") | ||
log.Infof("EtcdHost: %s", config.EtcdHost) | ||
log.Infof("EtcdPort: %s", config.EtcdPort) | ||
log.Infof("Endpoints: %v", endpoints) | ||
|
||
etcdClient, err := client.New(client.Config{ | ||
Endpoints: endpoints, | ||
Transport: client.DefaultTransport, | ||
HeaderTimeoutPerRequest: time.Second, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return etcdClient, nil | ||
} | ||
|
||
func etcdEndpoint(host string, port string) string { | ||
return fmt.Sprintf("http://%s:%s", host, port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters