Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set Reader to Body #6

Closed
wants to merge 3 commits into from
Closed

set Reader to Body #6

wants to merge 3 commits into from

Conversation

mattn
Copy link
Contributor

@mattn mattn commented May 18, 2024

bind stdin to Body in the struct. Now it's possible to upload S3 object like below.

$ ./aws-sdk-client-go s3 PutObject '{"bucket": "my-upload-test", "key":"ないしょ.txt"} < ないしょ.txt'

@fujiwara
Copy link
Owner

fujiwara commented May 20, 2024

@mattn Thank you! This is a great feature! But, I found a io.Reader field that is not named Body in another struct. For example lambda#InvokeAsyncInput.

I want to support these io.Reader fields by uniform flags (for example --bind-input Body=(filename or -). So, could you allow me to use the idea of this PR in my code? (of course I'll commit with co-author @mattn -san).

@mattn
Copy link
Contributor Author

mattn commented May 20, 2024

Yes, please

@mattn
Copy link
Contributor Author

mattn commented May 20, 2024

How can we set not only Body but also ContentType and ContentLength at the same time?

@fujiwara
Copy link
Owner

How can we set not only Body but also ContentType and ContentLength at the same time?

ContentType can be set into an Input struct as below.

$ aws-sdk-clent-go s3 PubObject '{"Bucket":"example","Key":"example","ContentType":"text/plain"}' ...

But ContentLength cannot be determined before it is read all from stdin.

For example, PutChunkInput has Data io.Reader and Length int64 fields, so we cannot generally decide the length field name.

As an idea, add --length-field=ContentLength to set the length after it is read all from stdin.

@fujiwara
Copy link
Owner

I searched Input structs that have io.Reader and *Length* fields from all.

2024/05/20 13:47:18 found io.Reader field in backupstorage.NotifyObjectCompleteInput MetadataBlob io.Reader
2024/05/20 13:47:18 found MetadataBlobLength field in backupstorage.NotifyObjectCompleteInput MetadataBlobLength MetadataBlobLength
2024/05/20 13:47:18 found io.Reader field in backupstorage.PutChunkInput Data io.Reader
2024/05/20 13:47:18 found Length field in backupstorage.PutChunkInput Length Length
2024/05/20 13:47:18 found io.Reader field in backupstorage.PutObjectInput InlineChunk io.Reader
2024/05/20 13:47:18 found InlineChunkLength field in backupstorage.PutObjectInput InlineChunkLength InlineChunkLength
2024/05/20 13:47:19 found io.Reader field in ebs.PutSnapshotBlockInput BlockData io.Reader
2024/05/20 13:47:19 found DataLength field in ebs.PutSnapshotBlockInput DataLength DataLength
2024/05/20 13:47:19 found io.Reader field in s3.PutObjectInput Body io.Reader
2024/05/20 13:47:19 found ContentLength field in s3.PutObjectInput ContentLength ContentLength
2024/05/20 13:47:19 found io.Reader field in s3.UploadPartInput Body io.Reader
2024/05/20 13:47:19 found ContentLength field in s3.UploadPartInput ContentLength ContentLength
2024/05/20 13:47:19 found io.Reader field in s3.WriteGetObjectResponseInput Body io.Reader
2024/05/20 13:47:19 found ContentLength field in s3.WriteGetObjectResponseInput ContentLength ContentLength

I think the length field can be set automatically by code generation.

@mattn
Copy link
Contributor Author

mattn commented May 20, 2024

If there will never be more than one Reader in a struct in the future, I see no problem with the --length-fied flag.

fujiwara added a commit that referenced this pull request May 24, 2024
Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
@fujiwara
Copy link
Owner

fujiwara commented May 24, 2024

@mattn Sorry, I've missed committing past. Added co-author by this commit. bf89ea2

@fujiwara fujiwara closed this May 24, 2024
@mattn
Copy link
Contributor Author

mattn commented May 24, 2024

No prob 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants