Skip to content

Commit

Permalink
Refactor Worker Client (#653)
Browse files Browse the repository at this point in the history
* worker: refactor client

* worker: remove ranged responsewriter, add ObjectEntriesOptions

* fix: TestMultipartUploads

* testing: fix TestMultipartUploads

* api: remove json tags

* api: rename to ApplyHeaders and ApplyValues
  • Loading branch information
peterjan authored Oct 13, 2023
1 parent 36f3334 commit a3360da
Show file tree
Hide file tree
Showing 13 changed files with 647 additions and 616 deletions.
26 changes: 13 additions & 13 deletions api/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,20 @@ type GougingParams struct {
// Option types.
type (
GetHostsOptions struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
Offset int
Limit int
}
HostsForScanningOptions struct {
MaxLastScan time.Time `json:"maxLastScan"`
Limit int `json:"limit"`
Offset int `json:"offset"`
MaxLastScan time.Time
Limit int
Offset int
}
SearchHostOptions struct {
AddressContains string `json:"addressContains"`
FilterMode string `json:"filterMode"`
KeyIn []types.PublicKey `json:"keyIn"`
Limit int `json:"limit"`
Offset int `json:"offset"`
AddressContains string
FilterMode string
KeyIn []types.PublicKey
Limit int
Offset int
}
)

Expand Down Expand Up @@ -430,8 +430,8 @@ func (opts HostsForScanningOptions) Apply(values url.Values) {
// Types related to multipart uploads.
type (
CreateMultipartOptions struct {
Key object.EncryptionKey `json:"key"`
MimeType string `json:"mimeType"`
Key object.EncryptionKey
MimeType string
}
MultipartCreateRequest struct {
Bucket string `json:"bucket"`
Expand Down Expand Up @@ -540,7 +540,7 @@ type (
}

CreateBucketOptions struct {
Policy BucketPolicy `json:"policy"`
Policy BucketPolicy
}
)

Expand Down
114 changes: 99 additions & 15 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,34 +128,118 @@ func (o ObjectMetadata) ContentType() string {

type (
AddObjectOptions struct {
MimeType string `json:"mimeType"`
ETag string `json:"eTag"`
MimeType string
ETag string
}

CopyObjectOptions struct {
MimeType string `json:"mimeType"`
MimeType string
}

DeleteObjectOptions struct {
Batch bool `json:"batch"`
Batch bool
}

DownloadObjectOptions struct {
Prefix string
Offset int
Limit int
Range DownloadRange
}

ObjectEntriesOptions struct {
Prefix string
Offset int
Limit int
}

GetObjectOptions struct {
Prefix string `json:"prefix"`
Offset int `json:"offset"`
Limit int `json:"limit"`
IgnoreDelim bool `json:"ignoreDelim"`
Marker string `json:"marker"`
Prefix string
Offset int
Limit int
IgnoreDelim bool
Marker string
}

ListObjectOptions struct {
Prefix string `json:"prefix"`
Marker string `json:"marker"`
Limit int `json:"limit"`
Prefix string
Marker string
Limit int
}

SearchObjectOptions struct {
Key string `json:"key"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Key string
Offset int
Limit int
}

UploadObjectOptions struct {
Offset int
MinShards int
TotalShards int
ContractSet string
MimeType string
DisablePreshardingEncryption bool
}

UploadMultipartUploadPartOptions struct {
DisablePreshardingEncryption bool
EncryptionOffset int
}
)

func (opts UploadObjectOptions) Apply(values url.Values) {
if opts.Offset != 0 {
values.Set("offset", fmt.Sprint(opts.Offset))
}
if opts.MinShards != 0 {
values.Set("minshards", fmt.Sprint(opts.MinShards))
}
if opts.TotalShards != 0 {
values.Set("totalshards", fmt.Sprint(opts.TotalShards))
}
if opts.ContractSet != "" {
values.Set("contractset", opts.ContractSet)
}
if opts.MimeType != "" {
values.Set("mimetype", opts.MimeType)
}
if opts.DisablePreshardingEncryption {
values.Set("disablepreshardingencryption", "true")
}
}

func (opts UploadMultipartUploadPartOptions) Apply(values url.Values) {
if opts.DisablePreshardingEncryption {
values.Set("disablepreshardingencryption", "true")
}
if !opts.DisablePreshardingEncryption || opts.EncryptionOffset != 0 {
values.Set("offset", fmt.Sprint(opts.EncryptionOffset))
}
}

func (opts DownloadObjectOptions) ApplyValues(values url.Values) {
if opts.Prefix != "" {
values.Set("prefix", opts.Prefix)
}
if opts.Offset != 0 {
values.Set("offset", fmt.Sprint(opts.Offset))
}
if opts.Limit != 0 {
values.Set("limit", fmt.Sprint(opts.Limit))
}
}

func (opts DownloadObjectOptions) ApplyHeaders(h http.Header) {
if opts.Range != (DownloadRange{}) {
if opts.Range.Length == -1 {
h.Set("Range", fmt.Sprintf("bytes=%v-", opts.Range.Offset))
} else {
h.Set("Range", fmt.Sprintf("bytes=%v-%v", opts.Range.Offset, opts.Range.Offset+opts.Range.Length-1))
}
}
}

func (opts DeleteObjectOptions) Apply(values url.Values) {
if opts.Batch {
values.Set("batch", "true")
Expand Down
Loading

0 comments on commit a3360da

Please sign in to comment.