Skip to content

Commit 07b8265

Browse files
committed
Code readability changes
1 parent 862b431 commit 07b8265

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

storage.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ func (cs ConsulStorage) Load(key string) ([]byte, error) {
154154

155155
kv, _, err := cs.ConsulClient.KV().Get(cs.prefixKey(key), &consul.QueryOptions{RequireConsistent: true})
156156
if err != nil {
157-
return nil, errors.Wrapf(err, "unable to obtain data for %s", cs.prefixKey(key))
158-
} else if kv == nil {
157+
return nil, certmagic.ErrNotExist(errors.Wrapf(err, "unable to obtain data for %s", cs.prefixKey(key)))
158+
}
159+
160+
if kv == nil {
159161
return nil, certmagic.ErrNotExist(errors.Errorf("key %s does not exist", cs.prefixKey(key)))
160162
}
161163

@@ -174,8 +176,10 @@ func (cs ConsulStorage) Delete(key string) error {
174176
// first obtain existing keypair
175177
kv, _, err := cs.ConsulClient.KV().Get(cs.prefixKey(key), &consul.QueryOptions{RequireConsistent: true})
176178
if err != nil {
177-
return errors.Wrapf(err, "unable to obtain data for %s", cs.prefixKey(key))
178-
} else if kv == nil {
179+
return certmagic.ErrNotExist(errors.Wrapf(err, "unable to obtain data for %s", cs.prefixKey(key)))
180+
}
181+
182+
if kv == nil {
179183
return certmagic.ErrNotExist(err)
180184
}
181185

@@ -205,7 +209,7 @@ func (cs ConsulStorage) List(prefix string, recursive bool) ([]string, error) {
205209
// get a list of all keys at prefix
206210
keys, _, err := cs.ConsulClient.KV().Keys(cs.prefixKey(prefix), "", &consul.QueryOptions{RequireConsistent: true})
207211
if err != nil {
208-
return keysFound, err
212+
return keysFound, certmagic.ErrNotExist(errors.Wrapf(err, "no keys at %s", prefix))
209213
}
210214

211215
if len(keys) == 0 {
@@ -245,7 +249,8 @@ func (cs ConsulStorage) Stat(key string) (certmagic.KeyInfo, error) {
245249
kv, _, err := cs.ConsulClient.KV().Get(cs.prefixKey(key), &consul.QueryOptions{RequireConsistent: true})
246250
if err != nil {
247251
return certmagic.KeyInfo{}, errors.Errorf("unable to obtain data for %s", cs.prefixKey(key))
248-
} else if kv == nil {
252+
}
253+
if kv == nil {
249254
return certmagic.KeyInfo{}, certmagic.ErrNotExist(errors.Errorf("key %s does not exist", cs.prefixKey(key)))
250255
}
251256

@@ -287,6 +292,7 @@ func (cs *ConsulStorage) createConsulClient() error {
287292
if err != nil {
288293
return errors.Wrap(err, "unable to create Consul client")
289294
}
295+
290296
if _, err := consulClient.Agent().NodeName(); err != nil {
291297
return errors.Wrap(err, "unable to ping Consul")
292298
}

0 commit comments

Comments
 (0)