From a90ccd82ac56f676ee15ea47ee439a4630251c30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Oct 2021 12:10:10 +0000 Subject: [PATCH 1/2] build(deps): bump github.com/dropbox/dropbox-sdk-go-unofficial/v6 Bumps [github.com/dropbox/dropbox-sdk-go-unofficial/v6](https://github.com/dropbox/dropbox-sdk-go-unofficial) from 6.0.2 to 6.0.3. - [Release notes](https://github.com/dropbox/dropbox-sdk-go-unofficial/releases) - [Commits](https://github.com/dropbox/dropbox-sdk-go-unofficial/compare/v6.0.2...v6.0.3) --- updated-dependencies: - dependency-name: github.com/dropbox/dropbox-sdk-go-unofficial/v6 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a6425e6..f01c78b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( github.com/beyondstorage/go-integration-test/v4 v4.6.0 github.com/beyondstorage/go-storage/v4 v4.8.0 - github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.2 + github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.3 github.com/google/uuid v1.3.0 golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 // indirect ) diff --git a/go.sum b/go.sum index 1ffda1b..b28cc38 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/dave/rebecca v0.9.1/go.mod h1:N6XYdMD/OKw3lkF3ywh8Z6wPGuwNFDNtWYEMFWE github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.2 h1:g7J3J9ppMgiMtV3OnjTWh0XPksfn5pzPtl4MWSpeWbc= -github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.2/go.mod h1:rSS3kM9XMzSQ6pw91Qgd6yB5jdt70N4OdtrAf74As5M= +github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.3 h1:h71/Ky9+298V45NSkxjhFv0aGsFOtPvqr25vbr5yMB0= +github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.3/go.mod h1:rSS3kM9XMzSQ6pw91Qgd6yB5jdt70N4OdtrAf74As5M= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= From 04f841ae04cadbb59c1ad0cc830d5c61be9ce23d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 5 Oct 2021 12:11:02 +0000 Subject: [PATCH 2/2] Auto build to generate code --- generated.go | 454 +++++++++++++-------------------------------------- 1 file changed, 117 insertions(+), 337 deletions(-) diff --git a/generated.go b/generated.go index 27c8e3b..1aa82ec 100644 --- a/generated.go +++ b/generated.go @@ -5,6 +5,7 @@ import ( "context" "io" "net/http" + "strings" "time" . "github.com/beyondstorage/go-storage/v4/pairs" @@ -13,19 +14,20 @@ import ( . "github.com/beyondstorage/go-storage/v4/types" ) -var _ Storager -var _ services.ServiceError -var _ httpclient.Options -var _ time.Duration -var _ http.Request -var _ Error +var ( + _ Storager + _ services.ServiceError + _ httpclient.Options + _ time.Duration + _ http.Request + _ Error +) // Type is the type for dropbox const Type = "dropbox" // ObjectSystemMetadata stores system metadata for object. type ObjectSystemMetadata struct { - // UploadSessionID a unique identifier for the upload session, refer to https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start UploadSessionID string } @@ -48,13 +50,15 @@ func setObjectSystemMetadata(o *Object, sm ObjectSystemMetadata) { o.SetSystemMetadata(sm) } -// StorageSystemMetadata stores system metadata for storage meta. +// StorageSystemMetadata stores system metadata for object. type StorageSystemMetadata struct { + UploadSessionID string } -// GetStorageSystemMetadata will get SystemMetadata from StorageMeta. +// GetStorageSystemMetadata will get StorageSystemMetadata from Storage. // -// - The returning StorageSystemMetadata is read only and should not be modified. +// - This function should not be called by service implementer. +// - The returning StorageServiceMetadata is read only and should not be modified. func GetStorageSystemMetadata(s *StorageMeta) StorageSystemMetadata { sm, ok := s.GetSystemMetadata() if ok { @@ -63,7 +67,7 @@ func GetStorageSystemMetadata(s *StorageMeta) StorageSystemMetadata { return StorageSystemMetadata{} } -// setStorageSystemMetadata will set SystemMetadata into StorageMeta. +// setStorageSystemMetadata will set StorageSystemMetadata into Storage. // // - This function should only be called once, please make sure all data has been written before set. func setStorageSystemMetadata(s *StorageMeta, sm StorageSystemMetadata) { @@ -72,48 +76,19 @@ func setStorageSystemMetadata(s *StorageMeta, sm StorageSystemMetadata) { // WithDefaultStoragePairs will apply default_storage_pairs value to Options. // -// DefaultStoragePairs set default pairs for storager actions +// set default pairs for storager actions func WithDefaultStoragePairs(v DefaultStoragePairs) Pair { - return Pair{ - Key: "default_storage_pairs", - Value: v, - } + return Pair{Key: "default_storage_pairs", Value: v} } // WithStorageFeatures will apply storage_features value to Options. // -// StorageFeatures set storage features +// set storage features func WithStorageFeatures(v StorageFeatures) Pair { - return Pair{ - Key: "storage_features", - Value: v, - } + return Pair{Key: "storage_features", Value: v} } -var pairMap = map[string]string{ - "content_md5": "string", - "content_type": "string", - "context": "context.Context", - "continuation_token": "string", - "credential": "string", - "default_content_type": "string", - "default_io_callback": "func([]byte)", - "default_storage_pairs": "DefaultStoragePairs", - "endpoint": "string", - "expire": "time.Duration", - "http_client_options": "*httpclient.Options", - "interceptor": "Interceptor", - "io_callback": "func([]byte)", - "list_mode": "ListMode", - "location": "string", - "multipart_id": "string", - "name": "string", - "object_mode": "ObjectMode", - "offset": "int64", - "size": "int64", - "storage_features": "StorageFeatures", - "work_dir": "string", -} +var pairMap = map[string]string{"content_md5": "string", "content_type": "string", "context": "context.Context", "continuation_token": "string", "credential": "string", "default_content_type": "string", "default_io_callback": "func([]byte)", "default_storage_pairs": "DefaultStoragePairs", "endpoint": "string", "expire": "time.Duration", "http_client_options": "*httpclient.Options", "interceptor": "Interceptor", "io_callback": "func([]byte)", "list_mode": "ListMode", "location": "string", "multipart_id": "string", "name": "string", "object_mode": "ObjectMode", "offset": "int64", "size": "int64", "storage_features": "StorageFeatures", "work_dir": "string"} var ( _ Appender = &Storage{} _ Direr = &Storage{} @@ -131,6 +106,10 @@ type pairStorageNew struct { HasCredential bool Credential string // Optional pairs + HasDefaultContentType bool + DefaultContentType string + HasDefaultIoCallback bool + DefaultIoCallback func([]byte) HasDefaultStoragePairs bool DefaultStoragePairs DefaultStoragePairs HasHTTPClientOptions bool @@ -140,29 +119,33 @@ type pairStorageNew struct { HasWorkDir bool WorkDir string // Enable features - // Default pairs - hasDefaultContentType bool - DefaultContentType string - hasDefaultIoCallback bool - DefaultIoCallback func([]byte) } // parsePairStorageNew will parse Pair slice into *pairStorageNew func parsePairStorageNew(opts []Pair) (pairStorageNew, error) { - result := pairStorageNew{ - pairs: opts, - } + result := + pairStorageNew{pairs: opts} for _, v := range opts { switch v.Key { - // Required pairs case "credential": if result.HasCredential { continue } result.HasCredential = true result.Credential = v.Value.(string) - // Optional pairs + case "default_content_type": + if result.HasDefaultContentType { + continue + } + result.HasDefaultContentType = true + result.DefaultContentType = v.Value.(string) + case "default_io_callback": + if result.HasDefaultIoCallback { + continue + } + result.HasDefaultIoCallback = true + result.DefaultIoCallback = v.Value.(func([]byte)) case "default_storage_pairs": if result.HasDefaultStoragePairs { continue @@ -187,40 +170,23 @@ func parsePairStorageNew(opts []Pair) (pairStorageNew, error) { } result.HasWorkDir = true result.WorkDir = v.Value.(string) - // Enable features - // Default pairs - case "default_content_type": - if result.hasDefaultContentType { - continue - } - result.hasDefaultContentType = true - result.DefaultContentType = v.Value.(string) - case "default_io_callback": - if result.hasDefaultIoCallback { - continue - } - result.hasDefaultIoCallback = true - result.DefaultIoCallback = v.Value.(func([]byte)) } } - // Enable features // Default pairs - if result.hasDefaultContentType { + if result.HasDefaultContentType { result.HasDefaultStoragePairs = true result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithContentType(result.DefaultContentType)) } - if result.hasDefaultIoCallback { + if result.HasDefaultIoCallback { result.HasDefaultStoragePairs = true result.DefaultStoragePairs.Read = append(result.DefaultStoragePairs.Read, WithIoCallback(result.DefaultIoCallback)) result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithIoCallback(result.DefaultIoCallback)) } - if !result.HasCredential { return pairStorageNew{}, services.PairRequiredError{Keys: []string{"credential"}} } - return result, nil } @@ -238,17 +204,15 @@ type DefaultStoragePairs struct { Write []Pair WriteAppend []Pair } - -// pairStorageCommitAppend is the parsed struct type pairStorageCommitAppend struct { pairs []Pair + // Required pairs + // Optional pairs } -// parsePairStorageCommitAppend will parse Pair slice into *pairStorageCommitAppend func (s *Storage) parsePairStorageCommitAppend(opts []Pair) (pairStorageCommitAppend, error) { - result := pairStorageCommitAppend{ - pairs: opts, - } + result := + pairStorageCommitAppend{pairs: opts} for _, v := range opts { switch v.Key { @@ -257,23 +221,20 @@ func (s *Storage) parsePairStorageCommitAppend(opts []Pair) (pairStorageCommitAp } } - // Check required pairs. - return result, nil } -// pairStorageCreate is the parsed struct type pairStorageCreate struct { - pairs []Pair + pairs []Pair + // Required pairs + // Optional pairs HasObjectMode bool ObjectMode ObjectMode } -// parsePairStorageCreate will parse Pair slice into *pairStorageCreate func (s *Storage) parsePairStorageCreate(opts []Pair) (pairStorageCreate, error) { - result := pairStorageCreate{ - pairs: opts, - } + result := + pairStorageCreate{pairs: opts} for _, v := range opts { switch v.Key { @@ -283,27 +244,23 @@ func (s *Storage) parsePairStorageCreate(opts []Pair) (pairStorageCreate, error) } result.HasObjectMode = true result.ObjectMode = v.Value.(ObjectMode) - continue default: return pairStorageCreate{}, services.PairUnsupportedError{Pair: v} } } - // Check required pairs. - return result, nil } -// pairStorageCreateAppend is the parsed struct type pairStorageCreateAppend struct { pairs []Pair + // Required pairs + // Optional pairs } -// parsePairStorageCreateAppend will parse Pair slice into *pairStorageCreateAppend func (s *Storage) parsePairStorageCreateAppend(opts []Pair) (pairStorageCreateAppend, error) { - result := pairStorageCreateAppend{ - pairs: opts, - } + result := + pairStorageCreateAppend{pairs: opts} for _, v := range opts { switch v.Key { @@ -312,21 +269,18 @@ func (s *Storage) parsePairStorageCreateAppend(opts []Pair) (pairStorageCreateAp } } - // Check required pairs. - return result, nil } -// pairStorageCreateDir is the parsed struct type pairStorageCreateDir struct { pairs []Pair + // Required pairs + // Optional pairs } -// parsePairStorageCreateDir will parse Pair slice into *pairStorageCreateDir func (s *Storage) parsePairStorageCreateDir(opts []Pair) (pairStorageCreateDir, error) { - result := pairStorageCreateDir{ - pairs: opts, - } + result := + pairStorageCreateDir{pairs: opts} for _, v := range opts { switch v.Key { @@ -335,23 +289,20 @@ func (s *Storage) parsePairStorageCreateDir(opts []Pair) (pairStorageCreateDir, } } - // Check required pairs. - return result, nil } -// pairStorageDelete is the parsed struct type pairStorageDelete struct { - pairs []Pair + pairs []Pair + // Required pairs + // Optional pairs HasObjectMode bool ObjectMode ObjectMode } -// parsePairStorageDelete will parse Pair slice into *pairStorageDelete func (s *Storage) parsePairStorageDelete(opts []Pair) (pairStorageDelete, error) { - result := pairStorageDelete{ - pairs: opts, - } + result := + pairStorageDelete{pairs: opts} for _, v := range opts { switch v.Key { @@ -361,29 +312,25 @@ func (s *Storage) parsePairStorageDelete(opts []Pair) (pairStorageDelete, error) } result.HasObjectMode = true result.ObjectMode = v.Value.(ObjectMode) - continue default: return pairStorageDelete{}, services.PairUnsupportedError{Pair: v} } } - // Check required pairs. - return result, nil } -// pairStorageList is the parsed struct type pairStorageList struct { - pairs []Pair + pairs []Pair + // Required pairs + // Optional pairs HasListMode bool ListMode ListMode } -// parsePairStorageList will parse Pair slice into *pairStorageList func (s *Storage) parsePairStorageList(opts []Pair) (pairStorageList, error) { - result := pairStorageList{ - pairs: opts, - } + result := + pairStorageList{pairs: opts} for _, v := range opts { switch v.Key { @@ -393,27 +340,23 @@ func (s *Storage) parsePairStorageList(opts []Pair) (pairStorageList, error) { } result.HasListMode = true result.ListMode = v.Value.(ListMode) - continue default: return pairStorageList{}, services.PairUnsupportedError{Pair: v} } } - // Check required pairs. - return result, nil } -// pairStorageMetadata is the parsed struct type pairStorageMetadata struct { pairs []Pair + // Required pairs + // Optional pairs } -// parsePairStorageMetadata will parse Pair slice into *pairStorageMetadata func (s *Storage) parsePairStorageMetadata(opts []Pair) (pairStorageMetadata, error) { - result := pairStorageMetadata{ - pairs: opts, - } + result := + pairStorageMetadata{pairs: opts} for _, v := range opts { switch v.Key { @@ -422,14 +365,13 @@ func (s *Storage) parsePairStorageMetadata(opts []Pair) (pairStorageMetadata, er } } - // Check required pairs. - return result, nil } -// pairStorageRead is the parsed struct type pairStorageRead struct { - pairs []Pair + pairs []Pair + // Required pairs + // Optional pairs HasIoCallback bool IoCallback func([]byte) HasOffset bool @@ -438,11 +380,9 @@ type pairStorageRead struct { Size int64 } -// parsePairStorageRead will parse Pair slice into *pairStorageRead func (s *Storage) parsePairStorageRead(opts []Pair) (pairStorageRead, error) { - result := pairStorageRead{ - pairs: opts, - } + result := + pairStorageRead{pairs: opts} for _, v := range opts { switch v.Key { @@ -452,43 +392,37 @@ func (s *Storage) parsePairStorageRead(opts []Pair) (pairStorageRead, error) { } result.HasIoCallback = true result.IoCallback = v.Value.(func([]byte)) - continue case "offset": if result.HasOffset { continue } result.HasOffset = true result.Offset = v.Value.(int64) - continue case "size": if result.HasSize { continue } result.HasSize = true result.Size = v.Value.(int64) - continue default: return pairStorageRead{}, services.PairUnsupportedError{Pair: v} } } - // Check required pairs. - return result, nil } -// pairStorageStat is the parsed struct type pairStorageStat struct { - pairs []Pair + pairs []Pair + // Required pairs + // Optional pairs HasObjectMode bool ObjectMode ObjectMode } -// parsePairStorageStat will parse Pair slice into *pairStorageStat func (s *Storage) parsePairStorageStat(opts []Pair) (pairStorageStat, error) { - result := pairStorageStat{ - pairs: opts, - } + result := + pairStorageStat{pairs: opts} for _, v := range opts { switch v.Key { @@ -498,20 +432,18 @@ func (s *Storage) parsePairStorageStat(opts []Pair) (pairStorageStat, error) { } result.HasObjectMode = true result.ObjectMode = v.Value.(ObjectMode) - continue default: return pairStorageStat{}, services.PairUnsupportedError{Pair: v} } } - // Check required pairs. - return result, nil } -// pairStorageWrite is the parsed struct type pairStorageWrite struct { - pairs []Pair + pairs []Pair + // Required pairs + // Optional pairs HasContentMd5 bool ContentMd5 string HasContentType bool @@ -520,11 +452,9 @@ type pairStorageWrite struct { IoCallback func([]byte) } -// parsePairStorageWrite will parse Pair slice into *pairStorageWrite func (s *Storage) parsePairStorageWrite(opts []Pair) (pairStorageWrite, error) { - result := pairStorageWrite{ - pairs: opts, - } + result := + pairStorageWrite{pairs: opts} for _, v := range opts { switch v.Key { @@ -534,41 +464,35 @@ func (s *Storage) parsePairStorageWrite(opts []Pair) (pairStorageWrite, error) { } result.HasContentMd5 = true result.ContentMd5 = v.Value.(string) - continue case "content_type": if result.HasContentType { continue } result.HasContentType = true result.ContentType = v.Value.(string) - continue case "io_callback": if result.HasIoCallback { continue } result.HasIoCallback = true result.IoCallback = v.Value.(func([]byte)) - continue default: return pairStorageWrite{}, services.PairUnsupportedError{Pair: v} } } - // Check required pairs. - return result, nil } -// pairStorageWriteAppend is the parsed struct type pairStorageWriteAppend struct { pairs []Pair + // Required pairs + // Optional pairs } -// parsePairStorageWriteAppend will parse Pair slice into *pairStorageWriteAppend func (s *Storage) parsePairStorageWriteAppend(opts []Pair) (pairStorageWriteAppend, error) { - result := pairStorageWriteAppend{ - pairs: opts, - } + result := + pairStorageWriteAppend{pairs: opts} for _, v := range opts { switch v.Key { @@ -577,29 +501,21 @@ func (s *Storage) parsePairStorageWriteAppend(opts []Pair) (pairStorageWriteAppe } } - // Check required pairs. - return result, nil } - -// CommitAppend will commit and finish an append process. -// -// This function will create a context by default. func (s *Storage) CommitAppend(o *Object, pairs ...Pair) (err error) { ctx := context.Background() return s.CommitAppendWithContext(ctx, o, pairs...) } - -// CommitAppendWithContext will commit and finish an append process. func (s *Storage) CommitAppendWithContext(ctx context.Context, o *Object, pairs ...Pair) (err error) { defer func() { - err = s.formatError("commit_append", err) + err = + s.formatError("commit_append", err) }() if !o.Mode.IsAppend() { err = services.ObjectModeInvalidError{Expected: ModeAppend, Actual: o.Mode} return } - pairs = append(pairs, s.defaultPairs.CommitAppend...) var opt pairStorageCommitAppend @@ -607,52 +523,24 @@ func (s *Storage) CommitAppendWithContext(ctx context.Context, o *Object, pairs if err != nil { return } - return s.commitAppend(ctx, o, opt) } - -// Create will create a new object without any api call. -// -// ## Behavior -// -// - Create SHOULD NOT send any API call. -// - Create SHOULD accept ObjectMode pair as object mode. -// -// This function will create a context by default. func (s *Storage) Create(path string, pairs ...Pair) (o *Object) { pairs = append(pairs, s.defaultPairs.Create...) var opt pairStorageCreate - // Ignore error while handling local funtions. + // Ignore error while handling local functions. opt, _ = s.parsePairStorageCreate(pairs) - return s.create(path, opt) } - -// CreateAppend will create an append object. -// -// ## Behavior -// -// - CreateAppend SHOULD create an appendable object with position 0 and size 0. -// - CreateAppend SHOULD NOT return an error as the object exist. -// - Service SHOULD check and delete the object if exists. -// -// This function will create a context by default. func (s *Storage) CreateAppend(path string, pairs ...Pair) (o *Object, err error) { ctx := context.Background() return s.CreateAppendWithContext(ctx, path, pairs...) } - -// CreateAppendWithContext will create an append object. -// -// ## Behavior -// -// - CreateAppend SHOULD create an appendable object with position 0 and size 0. -// - CreateAppend SHOULD NOT return an error as the object exist. -// - Service SHOULD check and delete the object if exists. func (s *Storage) CreateAppendWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error) { defer func() { - err = s.formatError("create_append", err, path) + err = + s.formatError("create_append", err, path) }() pairs = append(pairs, s.defaultPairs.CreateAppend...) @@ -662,22 +550,16 @@ func (s *Storage) CreateAppendWithContext(ctx context.Context, path string, pair if err != nil { return } - - return s.createAppend(ctx, path, opt) + return s.createAppend(ctx, strings.ReplaceAll(path, "\\", "/"), opt) } - -// CreateDir will create a new dir object. -// -// This function will create a context by default. func (s *Storage) CreateDir(path string, pairs ...Pair) (o *Object, err error) { ctx := context.Background() return s.CreateDirWithContext(ctx, path, pairs...) } - -// CreateDirWithContext will create a new dir object. func (s *Storage) CreateDirWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error) { defer func() { - err = s.formatError("create_dir", err, path) + err = + s.formatError("create_dir", err, path) }() pairs = append(pairs, s.defaultPairs.CreateDir...) @@ -687,42 +569,16 @@ func (s *Storage) CreateDirWithContext(ctx context.Context, path string, pairs . if err != nil { return } - - return s.createDir(ctx, path, opt) + return s.createDir(ctx, strings.ReplaceAll(path, "\\", "/"), opt) } - -// Delete will delete an object from service. -// -// ## Behavior -// -// - Delete only delete one and only one object. -// - Service DON'T NEED to support remove all. -// - User NEED to implement remove_all by themself. -// - Delete is idempotent. -// - Successful delete always return nil error. -// - Delete SHOULD never return `ObjectNotExist` -// - Delete DON'T NEED to check the object exist or not. -// -// This function will create a context by default. func (s *Storage) Delete(path string, pairs ...Pair) (err error) { ctx := context.Background() return s.DeleteWithContext(ctx, path, pairs...) } - -// DeleteWithContext will delete an object from service. -// -// ## Behavior -// -// - Delete only delete one and only one object. -// - Service DON'T NEED to support remove all. -// - User NEED to implement remove_all by themself. -// - Delete is idempotent. -// - Successful delete always return nil error. -// - Delete SHOULD never return `ObjectNotExist` -// - Delete DON'T NEED to check the object exist or not. func (s *Storage) DeleteWithContext(ctx context.Context, path string, pairs ...Pair) (err error) { defer func() { - err = s.formatError("delete", err, path) + err = + s.formatError("delete", err, path) }() pairs = append(pairs, s.defaultPairs.Delete...) @@ -732,34 +588,16 @@ func (s *Storage) DeleteWithContext(ctx context.Context, path string, pairs ...P if err != nil { return } - - return s.delete(ctx, path, opt) + return s.delete(ctx, strings.ReplaceAll(path, "\\", "/"), opt) } - -// List will return list a specific path. -// -// ## Behavior -// -// - Service SHOULD support default `ListMode`. -// - Service SHOULD implement `ListModeDir` without the check for `VirtualDir`. -// - Service DON'T NEED to `Stat` while in `List`. -// -// This function will create a context by default. func (s *Storage) List(path string, pairs ...Pair) (oi *ObjectIterator, err error) { ctx := context.Background() return s.ListWithContext(ctx, path, pairs...) } - -// ListWithContext will return list a specific path. -// -// ## Behavior -// -// - Service SHOULD support default `ListMode`. -// - Service SHOULD implement `ListModeDir` without the check for `VirtualDir`. -// - Service DON'T NEED to `Stat` while in `List`. func (s *Storage) ListWithContext(ctx context.Context, path string, pairs ...Pair) (oi *ObjectIterator, err error) { defer func() { - err = s.formatError("list", err, path) + err = + s.formatError("list", err, path) }() pairs = append(pairs, s.defaultPairs.List...) @@ -769,35 +607,24 @@ func (s *Storage) ListWithContext(ctx context.Context, path string, pairs ...Pai if err != nil { return } - - return s.list(ctx, path, opt) + return s.list(ctx, strings.ReplaceAll(path, "\\", "/"), opt) } - -// Metadata will return current storager metadata. -// -// This function will create a context by default. func (s *Storage) Metadata(pairs ...Pair) (meta *StorageMeta) { pairs = append(pairs, s.defaultPairs.Metadata...) var opt pairStorageMetadata - // Ignore error while handling local funtions. + // Ignore error while handling local functions. opt, _ = s.parsePairStorageMetadata(pairs) - return s.metadata(opt) } - -// Read will read the file's data. -// -// This function will create a context by default. func (s *Storage) Read(path string, w io.Writer, pairs ...Pair) (n int64, err error) { ctx := context.Background() return s.ReadWithContext(ctx, path, w, pairs...) } - -// ReadWithContext will read the file's data. func (s *Storage) ReadWithContext(ctx context.Context, path string, w io.Writer, pairs ...Pair) (n int64, err error) { defer func() { - err = s.formatError("read", err, path) + err = + s.formatError("read", err, path) }() pairs = append(pairs, s.defaultPairs.Read...) @@ -807,34 +634,16 @@ func (s *Storage) ReadWithContext(ctx context.Context, path string, w io.Writer, if err != nil { return } - - return s.read(ctx, path, w, opt) + return s.read(ctx, strings.ReplaceAll(path, "\\", "/"), w, opt) } - -// Stat will stat a path to get info of an object. -// -// ## Behavior -// -// - Stat SHOULD accept ObjectMode pair as hints. -// - Service COULD have different implementations for different object mode. -// - Service SHOULD check if returning ObjectMode is match -// -// This function will create a context by default. func (s *Storage) Stat(path string, pairs ...Pair) (o *Object, err error) { ctx := context.Background() return s.StatWithContext(ctx, path, pairs...) } - -// StatWithContext will stat a path to get info of an object. -// -// ## Behavior -// -// - Stat SHOULD accept ObjectMode pair as hints. -// - Service COULD have different implementations for different object mode. -// - Service SHOULD check if returning ObjectMode is match func (s *Storage) StatWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error) { defer func() { - err = s.formatError("stat", err, path) + err = + s.formatError("stat", err, path) }() pairs = append(pairs, s.defaultPairs.Stat...) @@ -844,36 +653,16 @@ func (s *Storage) StatWithContext(ctx context.Context, path string, pairs ...Pai if err != nil { return } - - return s.stat(ctx, path, opt) + return s.stat(ctx, strings.ReplaceAll(path, "\\", "/"), opt) } - -// Write will write data into a file. -// -// ## Behavior -// -// - Write SHOULD NOT return an error as the object exist. -// - Service that has native support for `overwrite` doesn't NEED to check the object exists or not. -// - Service that doesn't have native support for `overwrite` SHOULD check and delete the object if exists. -// - A successful write operation SHOULD be complete, which means the object's content and metadata should be the same as specified in write request. -// -// This function will create a context by default. func (s *Storage) Write(path string, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { ctx := context.Background() return s.WriteWithContext(ctx, path, r, size, pairs...) } - -// WriteWithContext will write data into a file. -// -// ## Behavior -// -// - Write SHOULD NOT return an error as the object exist. -// - Service that has native support for `overwrite` doesn't NEED to check the object exists or not. -// - Service that doesn't have native support for `overwrite` SHOULD check and delete the object if exists. -// - A successful write operation SHOULD be complete, which means the object's content and metadata should be the same as specified in write request. func (s *Storage) WriteWithContext(ctx context.Context, path string, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { defer func() { - err = s.formatError("write", err, path) + err = + s.formatError("write", err, path) }() pairs = append(pairs, s.defaultPairs.Write...) @@ -883,28 +672,21 @@ func (s *Storage) WriteWithContext(ctx context.Context, path string, r io.Reader if err != nil { return } - - return s.write(ctx, path, r, size, opt) + return s.write(ctx, strings.ReplaceAll(path, "\\", "/"), r, size, opt) } - -// WriteAppend will append content to an append object. -// -// This function will create a context by default. func (s *Storage) WriteAppend(o *Object, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { ctx := context.Background() return s.WriteAppendWithContext(ctx, o, r, size, pairs...) } - -// WriteAppendWithContext will append content to an append object. func (s *Storage) WriteAppendWithContext(ctx context.Context, o *Object, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { defer func() { - err = s.formatError("write_append", err) + err = + s.formatError("write_append", err) }() if !o.Mode.IsAppend() { err = services.ObjectModeInvalidError{Expected: ModeAppend, Actual: o.Mode} return } - pairs = append(pairs, s.defaultPairs.WriteAppend...) var opt pairStorageWriteAppend @@ -912,10 +694,8 @@ func (s *Storage) WriteAppendWithContext(ctx context.Context, o *Object, r io.Re if err != nil { return } - return s.writeAppend(ctx, o, r, size, opt) } - func init() { services.RegisterStorager(Type, NewStorager) services.RegisterSchema(Type, pairMap)