本文整理汇总了Golang中github.com/docker/libkv/store/consul.Register函数的典型用法代码示例。如果您正苦于以下问题:Golang Register函数的具体用法?Golang Register怎么用?Golang Register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setupConsul
func (s *ConsulSuite) setupConsul(c *check.C) {
s.createComposeProject(c, "consul")
s.composeProject.Start(c)
consul.Register()
kv, err := libkv.NewStore(
store.CONSUL,
[]string{s.composeProject.Container(c, "consul").NetworkSettings.IPAddress + ":8500"},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
if err != nil {
c.Fatal("Cannot create store consul")
}
s.kv = kv
// wait for consul
err = utils.Try(60*time.Second, func() error {
_, err := kv.Exists("test")
if err != nil {
return err
}
return nil
})
c.Assert(err, checker.IsNil)
}
示例2: NewBgpRouteManager
func NewBgpRouteManager(masterIface string, server net.IP, as string) *BgpRouteManager {
b := &BgpRouteManager{
ethIface: masterIface,
server: server,
neighborlist: map[string]string{},
asnum: as,
}
consul.Register()
client := "localhost:8500"
kv, err := libkv.NewStore(
store.CONSUL, // or "consul"
[]string{client},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
b.kv = kv
if err != nil {
log.Fatal("Cannot create store consul")
}
b.neighborkey = "bgpneighbor"
if exist, _ := kv.Exists(b.neighborkey); exist == false {
err := b.kv.Put(b.neighborkey, []byte("bgpneighbor"), &store.WriteOptions{IsDir: true})
if err != nil {
fmt.Errorf("Something went wrong when initializing key %v", b.neighborkey)
}
}
err = b.kv.Put(b.neighborkey+"/"+server.String(), []byte(as), nil)
if err != nil {
log.Errorf("Error trying to put value at key: %v", b.neighborkey)
}
return b
}
示例3: Init
// Init is exported
func Init() {
// Register to libkv
zookeeper.Register()
consul.Register()
etcd.Register()
// Register to internal Swarm discovery service
discovery.Register("zk", &Discovery{backend: store.ZK})
discovery.Register("consul", &Discovery{backend: store.CONSUL})
discovery.Register("etcd", &Discovery{backend: store.ETCD})
}
示例4: provide
func (provider *KvProvider) provide(configurationChan chan<- configMessage) error {
switch provider.StoreType {
case store.CONSUL:
consul.Register()
case store.ETCD:
etcd.Register()
case store.ZK:
zookeeper.Register()
case store.BOLTDB:
boltdb.Register()
default:
return errors.New("Invalid kv store: " + string(provider.StoreType))
}
kv, err := libkv.NewStore(
provider.StoreType,
[]string{provider.Endpoint},
&store.Config{
ConnectionTimeout: 30 * time.Second,
Bucket: "traefik",
},
)
if err != nil {
return err
}
if _, err := kv.List(""); err != nil {
return err
}
provider.kvclient = kv
if provider.Watch {
stopCh := make(chan struct{})
chanKeys, err := kv.WatchTree(provider.Prefix, stopCh)
if err != nil {
return err
}
go func() {
for {
<-chanKeys
configuration := provider.loadConfig()
if configuration != nil {
configurationChan <- configMessage{string(provider.StoreType), configuration}
}
defer close(stopCh)
}
}()
}
configuration := provider.loadConfig()
configurationChan <- configMessage{string(provider.StoreType), configuration}
return nil
}
示例5: New
func New(hosts []string, config *store.Config) (store.Store, error) {
consul.Register()
s, err := libkv.NewStore(
store.CONSUL,
hosts,
config,
)
if err != nil {
return nil, err
}
return &ConsulStorage{
GeneralStorage: general.New(s, string(store.CONSUL)),
}, nil
}
示例6: setupConsulTLS
func (s *ConsulSuite) setupConsulTLS(c *check.C) {
s.createComposeProject(c, "consul_tls")
s.composeProject.Start(c)
consul.Register()
clientTLS := &provider.ClientTLS{
CA: "resources/tls/ca.cert",
Cert: "resources/tls/consul.cert",
Key: "resources/tls/consul.key",
InsecureSkipVerify: true,
}
TLSConfig, err := clientTLS.CreateTLSConfig()
c.Assert(err, checker.IsNil)
kv, err := libkv.NewStore(
store.CONSUL,
[]string{s.composeProject.Container(c, "consul").NetworkSettings.IPAddress + ":8585"},
&store.Config{
ConnectionTimeout: 10 * time.Second,
TLS: TLSConfig,
},
)
if err != nil {
c.Fatal("Cannot create store consul")
}
s.kv = kv
// wait for consul
err = utils.Try(60*time.Second, func() error {
_, err := kv.Exists("test")
if err != nil {
return err
}
return nil
})
c.Assert(err, checker.IsNil)
}
示例7: EnableKVStore
func (gc *GetConf) EnableKVStore(opts *KVOptions) (*GetConf, error) {
switch strings.ToLower(opts.Backend) {
case "consul":
// Register consul store to libkv
consul.Register()
// Parse config
c := &store.Config{
TLS: opts.KVConfig.TLS,
ConnectionTimeout: opts.KVConfig.ConnectionTimeout,
Bucket: opts.KVConfig.Bucket,
PersistConnection: opts.KVConfig.PersistConnection,
}
if opts.KVConfig.ClientTLS != nil {
c.ClientTLS = &store.ClientTLSConfig{
CertFile: opts.KVConfig.ClientTLS.CertFile,
KeyFile: opts.KVConfig.ClientTLS.KeyFile,
CACertFile: opts.KVConfig.ClientTLS.CACertFile,
}
}
// Initialize a new store with consul
kv, err := libkv.NewStore(
store.CONSUL,
opts.URLs,
c,
)
if err != nil {
return gc, errors.New("cannot create store consul")
}
gc.KVStore = kv
default:
return gc, errors.New("unknown backend")
}
// Read options from KV Store
loadFromKV(gc, opts)
return gc, nil
}
示例8: init
func init() {
consul.Register()
zookeeper.Register()
etcd.Register()
boltdb.Register()
}
示例9: Provide
// Provide allows the provider to provide configurations to traefik
// using the given configuration channel.
func (provider *Consul) Provide(configurationChan chan<- types.ConfigMessage) error {
provider.StoreType = store.CONSUL
consul.Register()
return provider.provide(configurationChan)
}
示例10: init
func init() {
// Register consul store to libkv
consul.Register()
}
示例11: CreateStore
// CreateStore creates the KV store
func (provider *Consul) CreateStore() (store.Store, error) {
provider.storeType = store.CONSUL
consul.Register()
return provider.createStore()
}
示例12: registerKVStores
func registerKVStores() {
consul.Register()
zookeeper.Register()
etcd.Register()
boltdb.Register()
}
示例13: Provide
// Provide allows the provider to provide configurations to traefik
// using the given configuration channel.
func (provider *Consul) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints []types.Constraint) error {
provider.storeType = store.CONSUL
consul.Register()
return provider.provide(configurationChan, pool, constraints)
}
示例14: init
func init() {
consul.Register()
etcd.Register()
}
示例15: init
func init() {
etcd.Register()
consul.Register()
zookeeper.Register()
}