本文整理汇总了Golang中github.com/docker/libkv/store/etcd.Register函数的典型用法代码示例。如果您正苦于以下问题:Golang Register函数的具体用法?Golang Register怎么用?Golang Register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *EtcdSuite) SetUpTest(c *check.C) {
s.createComposeProject(c, "etcd")
s.composeProject.Start(c)
etcd.Register()
url := s.composeProject.Container(c, "etcd").NetworkSettings.IPAddress + ":2379"
kv, err := libkv.NewStore(
store.ETCD,
[]string{url},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
if err != nil {
c.Fatal("Cannot create store etcd")
}
s.kv = kv
// wait for etcd
err = utils.Try(60*time.Second, func() error {
_, err := kv.Exists("test")
if err != nil {
return fmt.Errorf("Etcd connection error to %s: %v", url, err)
}
return nil
})
c.Assert(err, checker.IsNil)
}
示例2: NewStore
func NewStore(machines []string, cmd *ServerCommand, keyspace string) *Storage {
etcd.Register()
clt, err := libkv.NewStore(store.ETCD, cmd.Config.BackendMachines, &store.Config{})
if err != nil {
panic(err)
}
_, err = clt.List(keyspace)
if err != store.ErrKeyNotFound && err != nil {
log.WithError(err).Fatal("store: Store backend not reachable")
}
cfg := client.Config{
Endpoints: machines,
Transport: client.DefaultTransport,
// set timeout per request to fail fast when the target endpoint is unavailable
HeaderTimeoutPerRequest: time.Second,
}
c, err := client.New(cfg)
if err != nil {
log.Fatal(err)
}
kapi := client.NewKeysAPI(c)
return &Storage{Client: clt, Kapi: kapi, command: cmd, keyspace: keyspace}
}
示例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) {
etcd.Register()
s, err := libkv.NewStore(
store.ETCD,
hosts,
config,
)
if err != nil {
return nil, err
}
return &EtcdStorage{
GeneralStorage: general.New(s, string(store.ETCD)),
}, nil
}
示例6: init
func init() {
etcd.Register()
consul.Register()
zookeeper.Register()
}
示例7: init
func init() {
consul.Register()
zookeeper.Register()
etcd.Register()
boltdb.Register()
}
示例8: Provide
// Provide allows the provider to provide configurations to traefik
// using the given configuration channel.
func (provider *Etcd) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
provider.storeType = store.ETCD
etcd.Register()
return provider.provide(configurationChan, pool)
}
示例9: init
func init() {
// Register to libkv
consul.Register()
etcd.Register()
}
示例10: registerKVStores
func registerKVStores() {
consul.Register()
zookeeper.Register()
etcd.Register()
boltdb.Register()
}
示例11: initLibKV
func initLibKV() {
etcd.Register()
}
示例13: main
func main() {
fmt.Println("start controller main()")
etcd_url_ptr := flag.String("etcd", "192.168.3.2:4001", "etcd url")
flag.Parse()
fmt.Println("etcd: ", *etcd_url_ptr)
h := PC_TopoHandler{}
topo.AddHandler(h)
topo.Init(*etcd_url_ptr)
IpContainerMapMutex = &sync.Mutex{}
IpContainerMap = make(map[string]*topo.ContainerInfo)
PodContainerListMutex = &sync.Mutex{}
PodContainerList = make(map[string]bwctl.QoS)
n := PC_NodeHandler{}
rest.AddHandler(n)
//for testing
pgreq0 := PGNetworkReq{"nginx", 0.4, 0.4, "Low", "Low", "Low", "Low", 0.4, 0.4, "Low", "Low", "Low", "Low"}
PGNetworkReqPool["nginx"] = pgreq0
netres0 := NodeNetworkRes{"node_0", 0.2, 1.0, "High", "Low", 1.0, 1.0, "High", "Low"}
netres1 := NodeNetworkRes{"node_1", 0.3, 1.0, "Low", "Low", 0.5, 1.0, "Low", "Low"}
netres2 := NodeNetworkRes{"node_2", 0.4, 1.0, "Low", "Low", 0.4, 1.0, "Low", "Low"}
netres3 := NodeNetworkRes{"node_3", 0.6, 1.0, "Low", "Low", 0.6, 1.0, "Low", "Low"}
netres4 := NodeNetworkRes{"node_4", 1.0, 1.0, "Low", "Low", 1.0, 1.0, "Low", "Low"}
nodeNetworkResPool["node_0"] = netres0
nodeNetworkResPool["node_1"] = netres1
nodeNetworkResPool["node_2"] = netres2
nodeNetworkResPool["node_3"] = netres3
nodeNetworkResPool["node_4"] = netres4
go rest.StartControllerRestServer(*etcd_url_ptr)
//scheduler plugin
go StartPluginRestServer()
// client := etcd.NewClient([]string{"192.168.3.2:4001"}) //http://127.0.0.1:4001 deploy.sh: K8S_NODE_IP
// parse_appChain()
// select{}
/* for { //waiting for update forever ...
watchChan := make(chan *etcd.Response)
go client.Watch("/0/public/appChain", 0, false, watchChan, nil)
log.Println("Waiting for an update...")
r := <-watchChan
log.Printf("Got updated appChain: %s: %s\n", r.Node.Key, r.Node.Value)
parse_appChain()
}*/
// We can register as many backends that are supported by libkv
etcd.Register()
client := "192.168.3.2:4001"
// Initialize a new store with consul kv, err := libkv.NewStore(
store.ETCD,
[]string{client},
&store.Config{
ConnectionTimeout: 10*time.Second,
},
)
if err != nil {
log.Fatal("Cannot create store")
}
//for qos testing
qos_key := "/0/52:54:00:c8:00:ab"
qosCtl := []bwctl.QoS{
{"192.0.0.1","1", "100", "1","all", "add", "1000", "1000", "1000", "1000", "0"},
{"192.0.0.1","1", "100", "1","default","add", "10", "100", "10", "100", "5"},
{"192.0.0.1","1", "100", "1","172.17.0.2","add", "500", "500", "700", "700", "0"},
{"192.0.0.2","2", "102", "2","172.17.0.3", "add","200", "200", "200", "200", "5"},
{"192.0.0.2","2", "102", "2","172.17.0.4", "add", "200", "200", "200", "200", "7"},
}
qos_encode, err := json.Marshal(qosCtl)
if err != nil {
log.Fatal(err)
}
//resp, err := kapi.Set(context.Background(), "/" + n.Name, string(qos_encode), nil)
err = kv.Put(qos_key, []byte(qos_encode), nil)
if err != nil {
log.Fatal("Error trying to put value at key `", qos_key, "`")
}
pair, err := kv.Get(qos_key)
if err != nil {
log.Fatal("Error trying accessing value at key `", qos_key, "`")
}
fmt.Println("value: ", string(pair.Value))
//for qos testing end
//.........这里部分代码省略.........
示例14: CreateStore
// CreateStore creates the KV store
func (provider *Etcd) CreateStore() (store.Store, error) {
provider.storeType = store.ETCD
etcd.Register()
return provider.createStore()
}
示例15: init
func init() {
etcd.Register()
consul.Register()
}