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

Implement AOS-47 & AOS-51 #8

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/aos-dev/go-service-uss
go 1.15

require (
github.com/aos-dev/go-storage/v3 v3.6.0
github.com/aos-dev/go-storage/v3 v3.6.1-0.20210510125045-f79d0505cb2b
github.com/upyun/go-sdk/v3 v3.0.2
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/Xuanwo/templateutils v0.1.0 h1:WpkWOqQtIQ2vAIpJLa727DdN8WtxhUkkbDGa6UhntJY=
github.com/Xuanwo/templateutils v0.1.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8=
github.com/aos-dev/go-storage/v3 v3.6.0 h1:ywjMvh320+esJH81MqB9nyuMNLW97Krujz2UiprC2ZM=
github.com/aos-dev/go-storage/v3 v3.6.0/go.mod h1:ZQwybmoCcTWUOWg+G15gT/NQJoI8G8KH1pF41TuJqYk=
github.com/aos-dev/specs/go v0.0.0-20210423110314-8361397c2bf3 h1:e65ozDhdfHfhnDpZF9SLcY5mwtAg/sAvNIUAkFd+4D0=
github.com/aos-dev/specs/go v0.0.0-20210423110314-8361397c2bf3/go.mod h1:gNah3KaPJEfysh7uCCX+sYjQC3g2yx2VgBkFlT945Ws=
github.com/aos-dev/go-storage/v3 v3.6.1-0.20210510125045-f79d0505cb2b h1:3XpTC+Q+bm2zVoEI67AUf52o28Loq8YcZ0L45F/2H4I=
github.com/aos-dev/go-storage/v3 v3.6.1-0.20210510125045-f79d0505cb2b/go.mod h1:ho7Z5P8fj+Q+9pCBng5s+d0XjH06I4hslaht9aiUjaA=
github.com/aos-dev/specs/go v0.0.0-20210510065836-ba70d7b05cda h1:D9DV8kz38iPT6mCHSCTlxYN4Zg9DUfHmWKJKVBvZmfY=
github.com/aos-dev/specs/go v0.0.0-20210510065836-ba70d7b05cda/go.mod h1:gNah3KaPJEfysh7uCCX+sYjQC3g2yx2VgBkFlT945Ws=
github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY=
github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU=
github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ=
Expand Down
4 changes: 2 additions & 2 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uss

import (
"context"
"fmt"
"io"
"strconv"
"sync"
Expand All @@ -11,6 +10,7 @@ import (

"github.com/aos-dev/go-storage/v3/pkg/headers"
"github.com/aos-dev/go-storage/v3/pkg/iowrap"
"github.com/aos-dev/go-storage/v3/services"
. "github.com/aos-dev/go-storage/v3/types"
)

Expand Down Expand Up @@ -69,7 +69,7 @@ func (s *Storage) list(ctx context.Context, path string, opt pairStorageList) (o
case opt.ListMode.IsPrefix():
nextFn = s.nextObjectPageByPrefix
default:
return nil, fmt.Errorf("invalid list mode")
return nil, services.ListModeInvalidError{Actual: opt.ListMode}
}

return NewObjectIterator(ctx, nextFn, input), nil
Expand Down
14 changes: 9 additions & 5 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewStorager(pairs ...typ.Pair) (typ.Storager, error) {
func newStorager(pairs ...typ.Pair) (store *Storage, err error) {
defer func() {
if err != nil {
err = &services.InitError{Op: "new_storager", Type: Type, Err: err, Pairs: pairs}
err = services.InitError{Op: "new_storager", Type: Type, Err: formatError(err), Pairs: pairs}
}
}()

Expand All @@ -56,7 +56,7 @@ func newStorager(pairs ...typ.Pair) (store *Storage, err error) {
return nil, err
}
if cp.Protocol() != credential.ProtocolHmac {
return nil, services.NewPairUnsupportedError(ps.WithCredential(opt.Credential))
return nil, services.PairUnsupportedError{Pair: ps.WithCredential(opt.Credential)}
}

operator, password := cp.Hmac()
Expand Down Expand Up @@ -86,6 +86,10 @@ func newStorager(pairs ...typ.Pair) (store *Storage, err error) {

// ref: https://help.upyun.com/knowledge-base/errno/
func formatError(err error) error {
if _, ok := err.(services.AosError); ok {
return err
}

fn := func(s string) bool {
return strings.Contains(err.Error(), `"code": `+s)
}
Expand All @@ -97,7 +101,7 @@ func formatError(err error) error {
case strings.Contains(err.Error(), "404"):
return fmt.Errorf("%w: %v", services.ErrObjectNotExist, err)
default:
return err
return fmt.Errorf("%w, %v", services.ErrUnexpected, err)
}
case fn("40400001"):
// 40400001: file or directory not found
Expand All @@ -108,7 +112,7 @@ func formatError(err error) error {
// 40300011: has no permission to delete
return fmt.Errorf("%w: %v", services.ErrPermissionDenied, err)
default:
return err
return fmt.Errorf("%w, %v", services.ErrUnexpected, err)
}
}

Expand All @@ -129,7 +133,7 @@ func (s *Storage) formatError(op string, err error, path ...string) error {
return nil
}

return &services.StorageError{
return services.StorageError{
Op: op,
Err: formatError(err),
Storager: s,
Expand Down