Skip to content

Commit

Permalink
BKTCLT-31 [squash] address review comments
Browse files Browse the repository at this point in the history
- Use references for options (also modified ListObjectVersions)

- Use url.URL object to create the full URL (also modified
  ListObjectVersions and CreateBucket)
  • Loading branch information
jonathan-gramain committed Oct 22, 2024
1 parent 2b13d95 commit b5bfa7d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
4 changes: 3 additions & 1 deletion go/createbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func (client *BucketClient) CreateBucket(ctx context.Context,
if parsedOpts.sessionId > 0 {
query.Set("raftsession", strconv.Itoa(parsedOpts.sessionId))
}
resource += "?" + query.Encode()
u, _ := url.Parse(resource)
u.RawQuery = query.Encode()
resource = u.String()
requestOptions := []RequestOption{
RequestBodyOption(bucketAttributes),
RequestBodyContentTypeOption("application/json"),
Expand Down
48 changes: 24 additions & 24 deletions go/listbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ type ListBasicOption func(*listBasicOptionSet) error
// ListBasicGTOption only lists keys greater than the given argument
func ListBasicGTOption(gt string) ListBasicOption {
return func(opts *listBasicOptionSet) error {
opts.gt = gt
opts.gt = &gt
return nil
}
}

// ListBasicGTEOption only lists keys greater or equal to the given argument
func ListBasicGTEOption(gte string) ListBasicOption {
return func(opts *listBasicOptionSet) error {
opts.gte = gte
opts.gte = &gte
return nil
}
}

// ListBasicLTOption only lists keys less than the given argument
func ListBasicLTOption(lt string) ListBasicOption {
return func(opts *listBasicOptionSet) error {
opts.lt = lt
opts.lt = &lt
return nil
}
}

// ListBasicLTEOption only lists keys less or equal to the given argument
func ListBasicLTEOption(lte string) ListBasicOption {
return func(opts *listBasicOptionSet) error {
opts.lte = lte
opts.lte = &lte
return nil
}
}
Expand All @@ -48,7 +48,7 @@ func ListBasicMaxKeysOption(maxKeys int) ListBasicOption {
if maxKeys < 0 || maxKeys > 10000 {
return fmt.Errorf("maxKeys=%d is out of the valid range [0, 10000]", maxKeys)
}
opts.maxKeys = maxKeys
opts.maxKeys = &maxKeys
return nil
}
}
Expand Down Expand Up @@ -83,19 +83,17 @@ type ListBasicEntry struct {
type ListBasicResponse []ListBasicEntry

type listBasicOptionSet struct {
gt string
gte string
lt string
lte string
maxKeys int
gt *string
gte *string
lt *string
lte *string
maxKeys *int
noKeys bool
noValues bool
}

func parseListBasicOptions(opts []ListBasicOption) (listBasicOptionSet, error) {
parsedOpts := listBasicOptionSet{
maxKeys: -1,
}
parsedOpts := listBasicOptionSet{}
for _, opt := range opts {
err := opt(&parsedOpts)
if err != nil {
Expand All @@ -117,28 +115,30 @@ func (client *BucketClient) ListBasic(ctx context.Context,
"ListBasic", "GET", client.Endpoint, resource, 0, "", err,
}
}
if options.gt != "" {
query.Set("gt", options.gt)
if options.gt != nil {
query.Set("gt", *options.gt)
}
if options.gte != "" {
query.Set("gte", options.gte)
if options.gte != nil {
query.Set("gte", *options.gte)
}
if options.lt != "" {
query.Set("lt", options.lt)
if options.lt != nil {
query.Set("lt", *options.lt)
}
if options.lte != "" {
query.Set("lte", options.lte)
if options.lte != nil {
query.Set("lte", *options.lte)
}
if options.maxKeys != -1 {
query.Set("maxKeys", strconv.Itoa(options.maxKeys))
if options.maxKeys != nil {
query.Set("maxKeys", strconv.Itoa(*options.maxKeys))
}
if options.noKeys {
query.Set("keys", "false")
}
if options.noValues {
query.Set("values", "false")
}
resource += "?" + query.Encode()
u, _ := url.Parse(resource)
u.RawQuery = query.Encode()
resource = u.String()
responseBody, err := client.Request(ctx, "ListBasic", "GET", resource)
if err != nil {
return nil, err
Expand Down
42 changes: 21 additions & 21 deletions go/listobjectversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type ListObjectVersionsOption func(*listObjectVersionsOptionSet) error

func ListObjectVersionsMarkerOption(keyMarker string, versionIdMarker string) ListObjectVersionsOption {
return func(opts *listObjectVersionsOptionSet) error {
opts.keyMarker = keyMarker
opts.versionIdMarker = versionIdMarker
opts.keyMarker = &keyMarker
opts.versionIdMarker = &versionIdMarker
return nil
}
}
Expand All @@ -23,7 +23,7 @@ func ListObjectVersionsMaxKeysOption(maxKeys int) ListObjectVersionsOption {
if maxKeys < 0 || maxKeys > 10000 {
return fmt.Errorf("maxKeys=%d is out of the valid range [0, 10000]", maxKeys)
}
opts.maxKeys = maxKeys
opts.maxKeys = &maxKeys
return nil
}
}
Expand All @@ -38,8 +38,8 @@ func ListObjectVersionsMaxKeysOption(maxKeys int) ListObjectVersionsOption {
// client.
func ListObjectVersionsLastMarkerOption(lastKeyMarker string, lastVersionIdMarker string) ListObjectVersionsOption {
return func(opts *listObjectVersionsOptionSet) error {
opts.lastKeyMarker = lastKeyMarker
opts.lastVersionIdMarker = lastVersionIdMarker
opts.lastKeyMarker = &lastKeyMarker
opts.lastVersionIdMarker = &lastVersionIdMarker
return nil
}
}
Expand All @@ -59,17 +59,15 @@ type ListObjectVersionsResponse struct {
}

type listObjectVersionsOptionSet struct {
keyMarker string
versionIdMarker string
maxKeys int
lastKeyMarker string
lastVersionIdMarker string
keyMarker *string
versionIdMarker *string
maxKeys *int
lastKeyMarker *string
lastVersionIdMarker *string
}

func parseListObjectVersionsOptions(opts []ListObjectVersionsOption) (listObjectVersionsOptionSet, error) {
parsedOpts := listObjectVersionsOptionSet{
maxKeys: -1,
}
parsedOpts := listObjectVersionsOptionSet{}
for _, opt := range opts {
err := opt(&parsedOpts)
if err != nil {
Expand All @@ -91,14 +89,16 @@ func (client *BucketClient) ListObjectVersions(ctx context.Context,
"ListObjectVersions", "GET", client.Endpoint, resource, 0, "", err,
}
}
if options.keyMarker != "" {
query.Set("keyMarker", options.keyMarker)
query.Set("versionIdMarker", options.versionIdMarker)
if options.keyMarker != nil {
query.Set("keyMarker", *options.keyMarker)
query.Set("versionIdMarker", *options.versionIdMarker)
}
if options.maxKeys != -1 {
query.Set("maxKeys", strconv.Itoa(options.maxKeys))
if options.maxKeys != nil {
query.Set("maxKeys", strconv.Itoa(*options.maxKeys))
}
resource += "?" + query.Encode()
u, _ := url.Parse(resource)
u.RawQuery = query.Encode()
resource = u.String()
responseBody, err := client.Request(ctx, "ListObjectVersions", "GET", resource)
if err != nil {
return nil, err
Expand All @@ -109,9 +109,9 @@ func (client *BucketClient) ListObjectVersions(ctx context.Context,
return nil, ErrorMalformedResponse("ListObjectVersions", "GET",
client.Endpoint, resource, jsonErr)
}
if options.lastKeyMarker != "" {
if options.lastKeyMarker != nil {
truncateListObjectVersionsResponse(parsedResponse,
options.lastKeyMarker, options.lastVersionIdMarker)
*options.lastKeyMarker, *options.lastVersionIdMarker)
}
return parsedResponse, nil
}

0 comments on commit b5bfa7d

Please sign in to comment.