本文整理汇总了Golang中github.com/docker/libkv/store.SplitKey函数的典型用法代码示例。如果您正苦于以下问题:Golang SplitKey函数的具体用法?Golang SplitKey怎么用?Golang SplitKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SplitKey函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:oldmantaiter,项目名称:dkron,代码行数:26,代码来源:store.go
示例2: AtomicPut
// AtomicPut put a value at "key" if the key has not been
// modified in the meantime, throws an error if this is the case
func (s *Zookeeper) AtomicPut(key string, value []byte, previous *store.KVPair, _ *store.WriteOptions) (bool, *store.KVPair, error) {
var lastIndex uint64
if previous != nil {
meta, err := s.client.Set(s.normalize(key), value, int32(previous.LastIndex))
if err != nil {
// Compare Failed
if err == zk.ErrBadVersion {
return false, nil, store.ErrKeyModified
}
return false, nil, err
}
lastIndex = uint64(meta.Version)
} else {
// Interpret previous == nil as create operation.
_, err := s.client.Create(s.normalize(key), value, 0, zk.WorldACL(zk.PermAll))
if err != nil {
// Directory does not exist
if err == zk.ErrNoNode {
// Create the directory
parts := store.SplitKey(strings.TrimSuffix(key, "/"))
parts = parts[:len(parts)-1]
if err = s.createFullPath(parts, false); err != nil {
// Failed to create the directory.
return false, nil, err
}
// Create the node
if _, err := s.client.Create(s.normalize(key), value, 0, zk.WorldACL(zk.PermAll)); err != nil {
// Node exist error (when previous nil)
if err == zk.ErrNodeExists {
return false, nil, store.ErrKeyExists
}
return false, nil, err
}
} else {
// Node Exists error (when previous nil)
if err == zk.ErrNodeExists {
return false, nil, store.ErrKeyExists
}
// Unhandled error
return false, nil, err
}
}
lastIndex = 0 // Newly created nodes have version 0.
}
pair := &store.KVPair{
Key: key,
Value: value,
LastIndex: lastIndex,
}
return true, pair, nil
}
开发者ID:Chandra-TechPassionate,项目名称:docker,代码行数:60,代码来源:zookeeper.go
示例3: Put
// Put a value at "key"
func (s *Zookeeper) Put(key string, value []byte, opts *store.WriteOptions) error {
fkey := store.Normalize(key)
exists, err := s.Exists(key)
if err != nil {
return err
}
if !exists {
if opts != nil && opts.Ephemeral {
s.createFullPath(store.SplitKey(key), opts.Ephemeral)
} else {
s.createFullPath(store.SplitKey(key), false)
}
}
_, err = s.client.Set(fkey, value, -1)
return err
}
开发者ID:fengbaicanhe,项目名称:docker,代码行数:20,代码来源:zookeeper.go
示例4: Put
// Put a value at "key"
func (s *Zookeeper) Put(key string, value []byte, opts *store.WriteOptions) error {
fkey := s.normalize(key)
exists, err := s.Exists(key)
if err != nil {
return err
}
if !exists {
if opts != nil && opts.TTL > 0 {
s.createFullPath(store.SplitKey(strings.TrimSuffix(key, "/")), true)
} else {
s.createFullPath(store.SplitKey(strings.TrimSuffix(key, "/")), false)
}
}
_, err = s.client.Set(fkey, value, -1)
return err
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:20,代码来源:zookeeper.go
注:本文中的github.com/docker/libkv/store.SplitKey函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论