Skip to content

Possible improvement on config.LoadDefaultConfig to accept existing config.LoadOptionsFunc type instead of dynamic function signature #2193

@migueleliasweb

Description

@migueleliasweb

Describe the bug

The function config.LoadDefaultConfig second parameter is typed optFns ...func(*LoadOptions) error instead of using the previouisly defined config.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 used config.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:

cannot use awsConfigOptions (variable of type []"github.com/aws/aws-sdk-go-v2/config".LoadOptionsFunc) as []func(*"github.com/aws/aws-sdk-go-v2/config".LoadOptions) error value in argument to awsConfig.LoadDefaultConfig

Reproduction Steps

// awsConfigOptions := []awsConfig.LoadOptionsFunc{} // this won't work properly as although the types are "the same" golang won't allow a runtime lambda-like function to match agaist a defined type signarture (afaik)
awsConfigOptions := []func(*awsConfig.LoadOptions) error{}

if config.Debug { // let's say config.Debug comes from the user's config
	awsConfigOptions = append(
		awsConfigOptions,
		awsConfig.WithClientLogMode(aws.LogRequestWithBody|aws.LogRequestEventMessage),
	)
}

cfg, err := awsConfig.LoadDefaultConfig(
	context.TODO(),
	awsConfigOptions...,
)

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

github.com/aws/aws-sdk-go-v2 v1.18.1

Compiler and Version used

go1.20.1 darwin/arm64

Operating System and version

MacOS

Metadata

Metadata

Assignees

Labels

feature-requestA feature should be added or improved.needs-triageThis issue or PR still needs to be triaged.p3This is a minor priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions