-
Notifications
You must be signed in to change notification settings - Fork 638
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
Possible improvement on config.LoadDefaultConfig to accept existing config.LoadOptionsFunc type instead of dynamic function signature #2193
Comments
If that helps, the definition for the function:
seems to be 3 days older (via git blame) than
Maybe this is just a matter of someone missing to come back and reuse the type defined at a later time. |
Also, note that this is not really a bug per se. The code can and will work normally. This is just a possible improvement. |
This fixes aws#2193.
I've opened a PR to address this at #2199. |
Unfortunately the proposed change is an API break since these two types are not interchangeable. Given the revised function definition: func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error) The reverse w.r.t. what is accepted by the call in question becomes true: // this now works
awsConfigOptions := []awsConfig.LoadOptionsFunc{}
// this is now broken
// awsConfigOptions := []func(*awsConfig.LoadOptions) error{}
if config.Debug {
awsConfigOptions = append(
awsConfigOptions,
awsConfig.WithClientLogMode(aws.LogRequestWithBody|aws.LogRequestEventMessage),
)
}
cfg, err := awsConfig.LoadDefaultConfig(
context.TODO(),
awsConfigOptions...,
) Closing since we're unable to make this change. |
|
@lucix-aws Is this something that can be addressed in the next major version of the SDK? |
Would making a type alias work, @lucix-aws ? |
@davidjb There won't be a new major semver version of the v2 SDK. The next effective "major version" would be a v3 of the Go SDK, which we currently have no plans to implement.
@migueleliasweb Can you clarify/provide an example of what you're envisioning? For the record -- I don't really see an issue with the API as it's defined now. Having to re-declare the signature may be slightly cumbersome, but you're still able to use the typedef and the explicit signature interchangeably when working with the actual slice. The example you've provided demonstrates this: if config.Debug {
awsConfigOptions = append(
awsConfigOptions,
// the return of `WithClientLogMode` is `LoadOptionsFunc`, but you can still pass it to
// the append call even though the slice is declared as `[]func(*LoadOptions) error`
awsConfig.WithClientLogMode(aws.LogRequestWithBody|aws.LogRequestEventMessage),
)
} |
Describe the bug
The function
config.LoadDefaultConfig
second parameter is typedoptFns ...func(*LoadOptions) error
instead of using the previouisly definedconfig.LoadOptionsFunc
.This forces users to redefine the whole type if they want to dinamically use the variadic options.
Expected Behavior
If the function
config.LoadDefaultConfig
usedconfig.LoadOptionsFunc
for its second parameter's type, this would make it a more elegant and concise code.Current Behavior
If a user tries to use
config.LoadOptionsFunc
they will get the following message:Reproduction Steps
Possible Solution
Make it so the function
LoadDefaultConfig
accepts a variadic type of[]awsConfig.LoadOptionsFunc{}
.Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
Compiler and Version used
go1.20.1 darwin/arm64
Operating System and version
MacOS
The text was updated successfully, but these errors were encountered: