Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

storage: Add appender support #12

Merged
merged 11 commits into from
May 7, 2021
3 changes: 1 addition & 2 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func (s *Storage) delete(ctx context.Context, path string, opt pairStorageDelete

_, err = s.client.DeleteV2(input)
if err != nil {
code := files.DeleteErrorPathLookup + "/" + files.LookupErrorNotFound
if ok := checkError(err, code); !ok {
if !checkError(err, files.DeleteErrorPathLookup, files.LookupErrorNotFound) {
Copy link
Contributor

@Xuanwo Xuanwo May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer:

if err != nil && checkError(err, files.DeleteErrorPathLookup, files.LookupErrorNotFound) {
    // leave comment here, refer to AOS-46
    err = nil
}
if err != nil {
    return err
}

return nil

return err
}
}
Expand Down
9 changes: 7 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ func formatError(err error) error {
return err
}

func checkError(err error, code string) bool {
return strings.Contains(err.Error(), code)
func checkError(err error, codes ...string) bool {
var errMsg strings.Builder
JinnyYi marked this conversation as resolved.
Show resolved Hide resolved
for _, code := range codes {
errMsg.WriteString(code)
errMsg.WriteString("/")
}
return strings.Contains(err.Error(), errMsg.String())
}

func (s *Storage) getAbsPath(path string) string {
Expand Down