Skip to content

Commit

Permalink
adjust certimagic returned error format (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
sillygod authored Apr 17, 2023
1 parent a8055c8 commit 688faa8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions extends/storage/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mystorage
import (
"context"
"fmt"
"io/fs"
"path"
"strings"

Expand Down Expand Up @@ -97,7 +98,7 @@ func (s *Storage) Load(ctx context.Context, key string) ([]byte, error) {
}

if kv == nil {
return nil, fmt.Errorf("key: %s does not exist", s.generateKey(key))
return nil, fs.ErrNotExist
}

return kv.Value, nil
Expand All @@ -112,6 +113,10 @@ func (s *Storage) Delete(ctx context.Context, key string) error {
return fmt.Errorf("unable to get data: %s, key: %s", err.Error(), s.generateKey(key))
}

if kv == nil {
return fs.ErrNotExist
}

success, _, err := s.KV.DeleteCAS(kv, nil)
if err != nil {
return fmt.Errorf("unable to delete data: %s, key: %s", err.Error(), s.generateKey(key))
Expand Down Expand Up @@ -145,7 +150,7 @@ func (s *Storage) List(ctx context.Context, prefix string, recursive bool) ([]st
}

if len(keys) == 0 {
return resultKeys, fmt.Errorf("no key at %s", prefix)
return resultKeys, fs.ErrNotExist
}

if recursive {
Expand Down Expand Up @@ -175,7 +180,7 @@ func (s *Storage) Stat(ctx context.Context, key string) (certmagic.KeyInfo, erro
}

if kv == nil {
return certmagic.KeyInfo{}, fmt.Errorf("key: %s does not exist", s.generateKey(key))
return certmagic.KeyInfo{}, fs.ErrNotExist
}

// what will happened if I don't give the modified time
Expand Down

0 comments on commit 688faa8

Please sign in to comment.