Skip to content

Method argument types require lots of boiler plate #265

Closed
@stevenh

Description

@stevenh

I'm looking at this new sdk as a replacement for goamz as its the official SDK; however the current structure, in particular the use of custom types, is far from ideal as it means anything interacting with the library needs to do have a significant amount of boiler plate all the time.

Here's a comparison
aws-sdk-go

svc := s3.New(&s3.Config{Credentials: auth, Region: region})
params := &s3.ListObjectsInput{
    Bucket:     aws.String(bucketName),
    Delimiter:  aws.String(delimiter),
    Prefix:     aws.String(prefix),
    MaxKeys:    aws.Long(max),
}
list, err := svc.ListObjects(params)

goamz

svc := s3.New(auth, region)
bucket := s3o.Bucket(bucketName)
list, err := svc.bucket.List(prefix, delimiter, marker, max)

I'm guessing the justification for the use of input types where multi values are required is API flexibility given the lack of overloading in go which is understandable, but the use of custom base types and structs with only a single field seems overkill.

As you can see from the above the amount of type conversion, hence boiler plate code, needed is significant in comparison to competing libraries.

Is there any way to make this so we can do the following, avoiding all the type conversion:

svc := s3.New(&s3.Config{Credentials: auth, Region: region})
params := &s3.ListObjectsInput{Bucket: bucketName,  Delimiter:  delimiter,  Prefix: prefix, MaxKeys: max}
list, err := svc.ListObjects(params)

Similarly for single value types:

svc := s3.New(nil)
params := &s3.GetBucketLocationInput{Bucket: aws.String(bucketName)}
resp, err := svc.GetBucketLocation(params)
if err != nil {
   return nil
}
fmt.Println(resp.LocationConstraint)

Would be much nicer if we could:

svc := s3.New(nil)
location, err := svc.GetBucketLocation(bucketName)
if err != nil {
   return nil
}
fmt.Println(location)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue is a duplicate.feature-requestA feature should be added or improved.guidanceQuestion that needs advice or information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions