本文整理汇总了Golang中github.com/coreos/etcd/client.IsKeyNotFound函数的典型用法代码示例。如果您正苦于以下问题:Golang IsKeyNotFound函数的具体用法?Golang IsKeyNotFound怎么用?Golang IsKeyNotFound使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsKeyNotFound函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetVariable
// GetVariable Gets a machine's variable, or the global if it was not
// set for the machine
func (m *etcdMachineInterface) GetVariable(key string) (string, error) {
value, err := m.selfGet(key)
if err != nil {
if !etcd.IsKeyNotFound(err) {
return "", fmt.Errorf(
"error while getting variable key=%s for machine=%s: %s",
key, m.mac, err)
}
// Key was not found for the machine
value, err := m.etcdDS.GetClusterVariable(key)
if err != nil {
if !etcd.IsKeyNotFound(err) {
return "", fmt.Errorf(
"error while getting variable key=%s for machine=%s (global check): %s",
key, m.mac, err)
}
return "", nil // Not set, not for machine, nor globally
}
return value, nil
}
return value, nil
}
示例2: GetTopicInfo
func (self *NsqLookupdEtcdMgr) GetTopicInfo(topic string, partition int) (*TopicPartitionMetaInfo, error) {
var topicInfo TopicPartitionMetaInfo
self.tmiMutex.Lock()
metaInfo, ok := self.topicMetaMap[topic]
if !ok {
rsp, err := self.client.Get(self.createTopicMetaPath(topic), false, false)
if err != nil {
self.tmiMutex.Unlock()
if client.IsKeyNotFound(err) {
atomic.StoreInt32(&self.ifTopicChanged, 1)
return nil, ErrKeyNotFound
}
return nil, err
}
var mInfo TopicMetaInfo
err = json.Unmarshal([]byte(rsp.Node.Value), &mInfo)
if err != nil {
self.tmiMutex.Unlock()
return nil, err
}
self.topicMetaMap[topic] = &mInfo
metaInfo = &mInfo
}
self.tmiMutex.Unlock()
topicInfo.TopicMetaInfo = *metaInfo
rsp, err := self.client.Get(self.createTopicReplicaInfoPath(topic, partition), false, false)
if err != nil {
if client.IsKeyNotFound(err) {
atomic.StoreInt32(&self.ifTopicChanged, 1)
return nil, ErrKeyNotFound
}
return nil, err
}
var rInfo TopicPartitionReplicaInfo
if err = json.Unmarshal([]byte(rsp.Node.Value), &rInfo); err != nil {
return nil, err
}
rInfo.Epoch = EpochType(rsp.Node.ModifiedIndex)
topicInfo.TopicPartitionReplicaInfo = rInfo
topicInfo.Name = topic
topicInfo.Partition = partition
return &topicInfo, nil
}
示例3: ReleaseTopicLeader
func (self *NsqdEtcdMgr) ReleaseTopicLeader(topic string, partition int, session *TopicLeaderSession) error {
self.Lock()
defer self.Unlock()
topicKey := self.createTopicLeaderPath(topic, partition)
valueB, err := json.Marshal(session)
if err != nil {
return err
}
_, err = self.client.CompareAndDelete(topicKey, string(valueB), 0)
if err != nil {
if !client.IsKeyNotFound(err) {
coordLog.Errorf("try release topic leader session [%s] error: %v, orig: %v", topicKey, err, session)
// since the topic leader session type is changed, we need do the compatible check
rsp, innErr := self.client.Get(topicKey, false, false)
if innErr != nil {
} else {
var old TopicLeaderSessionOld
json.Unmarshal([]byte(rsp.Node.Value), &old)
if old.IsEqual(session) {
_, err = self.client.CompareAndDelete(topicKey, rsp.Node.Value, 0)
}
}
}
}
if err == nil {
coordLog.Infof("try release topic leader session [%s] success: %v", topicKey, session)
}
return err
}
示例4: Machine
// Machine creates a record for the associated mac if needed
// and asked for, and returns a Machine with the stored values.
// If createIfNeeded is true, and there is no machine associated to
// this mac, the machine will be created, stored, and returned.
// In this case, if createWithIP is empty, the IP will be assigned
// automatically, otherwise the given will be used. An error will be
// raised if createWithIP is currently assigned to another mac. Also
// the Type will be automatically set to MTNormal if createWithIP is
// nil, otherwise to MTStatic.
// If createIfNeeded is false, the createWithIP is expected to be nil.
// Note: if the machine exists, createWithIP is ignored. It's possible
// for the returned Machine to have an IP different from createWithIP.
func (m *etcdMachineInterface) Machine(createIfNeeded bool,
createWithIP net.IP) (Machine, error) {
var machine Machine
if !createIfNeeded && (createWithIP != nil) {
return machine, errors.New(
"if createIfNeeded is false, the createWithIP is expected to be nil")
}
resp, err := m.selfGet("_machine")
if err != nil {
errorIsKeyNotFound := etcd.IsKeyNotFound(err)
if !(errorIsKeyNotFound && createIfNeeded) {
return machine, fmt.Errorf("error while retrieving _machine: %s", err)
}
machine := Machine{
IP: createWithIP, // to be assigned automatically
FirstSeen: time.Now().Unix(),
}
err := m.store(&machine)
if err != nil {
return machine, fmt.Errorf("error while storing _machine: %s", err)
}
return machine, nil
}
json.Unmarshal([]byte(resp), &machine)
return machine, nil
}
示例5: GetTopicInfo
func (self *NsqdEtcdMgr) GetTopicInfo(topic string, partition int) (*TopicPartitionMetaInfo, error) {
var topicInfo TopicPartitionMetaInfo
rsp, err := self.client.Get(self.createTopicMetaPath(topic), false, false)
if err != nil {
if client.IsKeyNotFound(err) {
return nil, ErrKeyNotFound
}
return nil, err
}
var mInfo TopicMetaInfo
err = json.Unmarshal([]byte(rsp.Node.Value), &mInfo)
if err != nil {
return nil, err
}
topicInfo.TopicMetaInfo = mInfo
rsp, err = self.client.Get(self.createTopicReplicaInfoPath(topic, partition), false, false)
if err != nil {
return nil, err
}
var rInfo TopicPartitionReplicaInfo
if err = json.Unmarshal([]byte(rsp.Node.Value), &rInfo); err != nil {
return nil, err
}
rInfo.Epoch = EpochType(rsp.Node.ModifiedIndex)
topicInfo.TopicPartitionReplicaInfo = rInfo
topicInfo.Name = topic
topicInfo.Partition = partition
return &topicInfo, nil
}
示例6: MkDir
// MkDir creates an empty etcd directory
func (etcdClient *SimpleEtcdClient) MkDir(directory string) error {
api := client.NewKeysAPI(etcdClient.etcd)
results, err := api.Get(context.Background(), directory, nil)
if err != nil && !client.IsKeyNotFound(err) {
return err
}
if err != nil && client.IsKeyNotFound(err) {
_, err = api.Set(context.Background(), directory, "", &client.SetOptions{Dir: true, PrevExist: client.PrevIgnore})
return err
}
if !results.Node.Dir {
return fmt.Errorf("Refusing to overwrite key/value with a directory: %v", directory)
}
return nil
}
示例7: RepoUserExistsByEmail
func RepoUserExistsByEmail(email string) (bool, string, error) {
userId, err := RepoGetUserIdByEmail(email)
if err != nil {
if client.IsKeyNotFound(err) != true {
return false, userId, err
}
return false, userId, nil
}
return true, userId, nil
}
示例8: Del
// Del deletes a key from Etcd
func (etcdClient *SimpleEtcdClient) Del(key string) error {
api := client.NewKeysAPI(etcdClient.etcd)
_, err := api.Delete(context.Background(), key, nil)
if err != nil {
if client.IsKeyNotFound(err) {
return nil
}
}
return err
}
示例9: DelDir
// DelDir deletes a dir from Etcd
func (etcdClient *SimpleEtcdClient) DelDir(key string) error {
api := client.NewKeysAPI(etcdClient.etcd)
_, err := api.Delete(context.Background(), key, &client.DeleteOptions{Dir: true, Recursive: true})
if err != nil {
if client.IsKeyNotFound(err) {
return nil
}
}
return err
}
示例10: RepoDomainExistsByName
func RepoDomainExistsByName(name string) (bool, Domain, error) {
domain, err := RepoGetDomainByName(name)
if err != nil {
if client.IsKeyNotFound(err) != true {
return false, domain, err
}
return false, domain, nil
}
return true, domain, nil
}
示例11: GetClusterEpoch
func (self *NsqLookupdEtcdMgr) GetClusterEpoch() (EpochType, error) {
rsp, err := self.client.Get(self.clusterPath, false, false)
if err != nil {
if client.IsKeyNotFound(err) {
return 0, ErrKeyNotFound
}
return 0, err
}
return EpochType(rsp.Node.ModifiedIndex), nil
}
示例12: Get
// Get gets a value in Etcd
func (etcdClient *SimpleEtcdClient) Get(key string) (string, error) {
api := client.NewKeysAPI(etcdClient.etcd)
response, err := api.Get(context.Background(), key, nil)
if err != nil {
if client.IsKeyNotFound(err) {
return "", nil
}
return "", err
}
return response.Node.Value, nil
}
示例13: LsRecursive
// LsRecursive returns all the keys available in the directory, recursively
func (etcdClient *SimpleEtcdClient) LsRecursive(directory string) ([]string, error) {
api := client.NewKeysAPI(etcdClient.etcd)
options := &client.GetOptions{Sort: true, Recursive: true}
response, err := api.Get(context.Background(), directory, options)
if err != nil {
if client.IsKeyNotFound(err) {
return make([]string, 0), nil
}
return make([]string, 0), err
}
return nodesToStringSlice(response.Node.Nodes), nil
}
示例14: GetTopicLeaderSession
func (self *NsqdEtcdMgr) GetTopicLeaderSession(topic string, partition int) (*TopicLeaderSession, error) {
rsp, err := self.client.Get(self.createTopicLeaderPath(topic, partition), false, false)
if err != nil {
if client.IsKeyNotFound(err) {
return nil, ErrKeyNotFound
}
return nil, err
}
var topicLeaderSession TopicLeaderSession
if err = json.Unmarshal([]byte(rsp.Node.Value), &topicLeaderSession); err != nil {
return nil, err
}
return &topicLeaderSession, nil
}
示例15: GetTopicMetaInfo
func (self *NsqLookupdEtcdMgr) GetTopicMetaInfo(topic string) (TopicMetaInfo, EpochType, error) {
var metaInfo TopicMetaInfo
rsp, err := self.client.Get(self.createTopicMetaPath(topic), false, false)
if err != nil {
if client.IsKeyNotFound(err) {
return metaInfo, 0, ErrKeyNotFound
}
return metaInfo, 0, err
}
err = json.Unmarshal([]byte(rsp.Node.Value), &metaInfo)
if err != nil {
return metaInfo, 0, err
}
epoch := EpochType(rsp.Node.ModifiedIndex)
return metaInfo, epoch, nil
}