forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move backend selection to backends package
- Loading branch information
1 parent
f0ee4b5
commit 30d6d8a
Showing
4 changed files
with
35 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
package backends | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/kelseyhightower/confd/backends/consul" | ||
"github.com/kelseyhightower/confd/backends/env" | ||
"github.com/kelseyhightower/confd/backends/etcd/etcdutil" | ||
"github.com/kelseyhightower/confd/config" | ||
"github.com/kelseyhightower/confd/log" | ||
) | ||
|
||
// The StoreClient interface is implemented by objects that can retrieve | ||
// key/value pairs from a backend store. | ||
type StoreClient interface { | ||
GetValues(keys []string) (map[string]interface{}, error) | ||
} | ||
|
||
// New is used to create a storage client based on our configuration. | ||
func New(backend string) (StoreClient, error) { | ||
if backend == "" { | ||
backend = "etcd" | ||
} | ||
switch backend { | ||
case "consul": | ||
log.Notice("Consul address set to " + config.ConsulAddr()) | ||
return consul.NewConsulClient(config.ConsulAddr()) | ||
case "etcd": | ||
// Create the etcd client upfront and use it for the life of the process. | ||
// The etcdClient is an http.Client and designed to be reused. | ||
log.Notice("etcd nodes set to " + strings.Join(config.EtcdNodes(), ", ")) | ||
return etcdutil.NewEtcdClient(config.EtcdNodes(), config.ClientCert(), config.ClientKey(), config.ClientCaKeys()) | ||
case "env": | ||
return env.NewEnvClient() | ||
} | ||
return nil, errors.New("Invalid backend") | ||
} |
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
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