本文整理汇总了Golang中github.com/docker/libkv/store.Backend函数的典型用法代码示例。如果您正苦于以下问题:Golang Backend函数的具体用法?Golang Backend怎么用?Golang Backend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Backend函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetExecutions
func (s *Store) GetExecutions(jobName string) ([]*Execution, error) {
prefix := fmt.Sprintf("%s/executions/%s", s.keyspace, jobName)
res, err := s.Client.List(prefix)
if err != nil {
return nil, err
}
var executions []*Execution
for _, node := range res {
if store.Backend(s.backend) != store.ZK {
path := store.SplitKey(node.Key)
dir := path[len(path)-2]
if dir != jobName {
continue
}
}
var execution Execution
err := json.Unmarshal([]byte(node.Value), &execution)
if err != nil {
return nil, err
}
executions = append(executions, &execution)
}
return executions, nil
}
示例2: NewStore
func NewStore(backend string, machines []string, a *AgentCommand, keyspace string) *Store {
store, err := libkv.NewStore(store.Backend(backend), machines, nil)
if err != nil {
log.Fatal(err)
}
return &Store{Client: store, agent: a, keyspace: keyspace}
}
示例3: New
func New(backend string) (store.Store, error) {
var storage store.Backend
var factory func(hosts []string, config *store.Config) (store.Store, error)
u, err := url.Parse(backend)
if err != nil {
return nil, err
}
storage = store.Backend(u.Scheme)
switch storage {
case store.CONSUL:
factory = consulStorage.New
case store.ETCD:
factory = etcdStorage.New
case store.ZK:
factory = zookeeperStorage.New
case store.BOLTDB:
factory = boltdbStorage.New
default:
storage = "unknow"
}
return factory([]string{u.Host}, &store.Config{
ConnectionTimeout: 10 * time.Second,
})
}
示例4: newClient
// newClient used to connect to KV Store
func newClient(kv string, addrs string) (DataStore, error) {
store, err := libkv.NewStore(store.Backend(kv), []string{addrs}, &store.Config{})
if err != nil {
return nil, err
}
ds := &datastore{store: store}
return ds, nil
}
示例5: NewStore
func NewStore(storeUrl string) (store.Store, error) {
kv, addrs := parseStoreUrl(storeUrl)
config := &store.Config{}
st, err := libkv.NewStore(store.Backend(kv), addrs, config)
if err != nil {
return nil, err
}
return st, nil
}
示例6: New
func New(config *config.BalancerConfig) (Store, error) {
u, err := url.Parse(config.StoreAddress)
if err != nil {
return nil, errors.Wrap(err, "error paring store address")
}
scheme := u.Scheme
if scheme != "consul" && scheme != "etcd" {
return nil, ErrUnsupportedStore
}
//Validating open connection
_, err = net.Dial("tcp", u.Host)
if err != nil {
return nil, errors.Wrap(err, "Store connection failed. Make sure your store is up and running.")
}
kv, err := libkv.NewStore(
kv.Backend(scheme),
[]string{u.Host},
nil,
)
if err != nil {
kv.Close()
return nil, errors.Wrap(err, "Cannot create store consul")
}
svcsChs := []chan []types.Service{}
dstsChs := []chan []types.Destination{}
checksChs := []chan []types.CheckSpec{}
validate := validator.New()
// Registering custom validations
validate.RegisterValidation("protocols", validateValues(types.Protocols))
validate.RegisterValidation("schedulers", validateValues(types.Schedulers))
fusisStore := &FusisStore{
kv: kv,
prefix: config.StorePrefix,
validate: validate,
servicesChannels: svcsChs,
destinationChannels: dstsChs,
checksChannels: checksChs,
}
go fusisStore.WatchServices()
go fusisStore.WatchDestinations()
go fusisStore.WatchChecks()
return fusisStore, nil
}
示例7: NewStore
func NewStore(backend string, machines []string, a *AgentCommand, keyspace string) *Store {
s, err := libkv.NewStore(store.Backend(backend), machines, nil)
if err != nil {
log.Fatal(err)
}
log.WithFields(logrus.Fields{
"backend": backend,
"machines": machines,
"keyspace": keyspace,
}).Debug("store: Backend config")
_, err = s.List(keyspace)
if err != store.ErrKeyNotFound && err != nil {
log.WithError(err).Fatal("store: Store backend not reachable")
}
return &Store{Client: s, agent: a, keyspace: keyspace, backend: backend}
}
示例8: newClient
// newClient used to connect to KV Store
func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error) {
if cached && scope != LocalScope {
return nil, fmt.Errorf("caching supported only for scope %s", LocalScope)
}
sequential := false
if scope == LocalScope {
sequential = true
}
if config == nil {
config = &store.Config{}
}
var addrs []string
if kv == string(store.BOLTDB) {
// Parse file path
addrs = strings.Split(addr, ",")
} else {
// Parse URI
parts := strings.SplitN(addr, "/", 2)
addrs = strings.Split(parts[0], ",")
// Add the custom prefix to the root chain
if len(parts) == 2 {
rootChain = append([]string{parts[1]}, defaultRootChain...)
}
}
store, err := libkv.NewStore(store.Backend(kv), addrs, config)
if err != nil {
return nil, err
}
ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{}), sequential: sequential}
if cached {
ds.cache = newCache(ds)
}
return ds, nil
}
示例9: newClient
// newClient used to connect to KV Store
func newClient(scope string, kv string, addrs string, config *store.Config, cached bool) (DataStore, error) {
if cached && scope != LocalScope {
return nil, fmt.Errorf("caching supported only for scope %s", LocalScope)
}
if config == nil {
config = &store.Config{}
}
store, err := libkv.NewStore(store.Backend(kv), []string{addrs}, config)
if err != nil {
return nil, err
}
ds := &datastore{scope: scope, store: store}
if cached {
ds.cache = newCache(ds)
}
return ds, nil
}
示例10: newClient
// newClient used to connect to KV Store
func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error) {
if cached && scope != LocalScope {
return nil, fmt.Errorf("caching supported only for scope %s", LocalScope)
}
if config == nil {
config = &store.Config{}
}
addrs := strings.Split(addr, ",")
store, err := libkv.NewStore(store.Backend(kv), addrs, config)
if err != nil {
return nil, err
}
ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{})}
if cached {
ds.cache = newCache(ds)
}
return ds, nil
}