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

Add accountID into endpoint2.0 param binding #496

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;

import java.util.ArrayList;
import software.amazon.smithy.go.codegen.GoStdlibTypes;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator;
import software.amazon.smithy.utils.MapUtils;
Expand All @@ -42,7 +43,7 @@ public GoWriter.Writable generate() {
loadResolvers();

return goTemplate("""
func $name:L(operation string, input interface{}, options Options) $params:P {
func $name:L(operation string, input interface{}, options Options, ctx $context:T) $params:P {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context, as a rule, goes first in an API's argument list.

params := &$params:T{
Operation: operation,
}
Expand All @@ -55,14 +56,15 @@ public GoWriter.Writable generate() {
MapUtils.of(
"name", FUNC_NAME,
"params", AuthParametersGenerator.STRUCT_SYMBOL,
"bindings", generateResolvers()
"bindings", generateResolvers(),
"context", GoStdlibTypes.Context.Context
));
}

private GoWriter.Writable generateResolvers() {
return (writer) -> {
for (var resolver: resolvers) {
writer.write("$T(params, input, options)", resolver.resolver());
writer.write("$T(params, input, options, ctx)", resolver.resolver());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private GoWriter.Writable generateFields() {

private GoWriter.Writable generateBody() {
return goTemplate("""
params := $1L(m.operation, getOperationInput(ctx), m.options)
params := $1L(m.operation, getOperationInput(ctx), m.options, ctx)
options, err := m.options.AuthSchemeResolver.ResolveAuthSchemes(ctx, params)
if err != nil {
return out, metadata, $2T("resolve auth scheme: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private GoWriter.Writable generateAssertResolver() {

private GoWriter.Writable generateResolveEndpoint() {
return goTemplate("""
params := bindEndpointParams(getOperationInput(ctx), m.options)
params := bindEndpointParams(getOperationInput(ctx), m.options, ctx)
endpt, err := m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params)
if err != nil {
return out, metadata, $1T("failed to resolve service endpoint, %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public GoWriter.Writable generate() {
bindEndpointParams(*EndpointParameters)
}

func bindEndpointParams(input interface{}, options Options) *EndpointParameters {
func bindEndpointParams(input interface{}, options Options, ctx context.Context) *EndpointParameters {
params := &EndpointParameters{}

$builtinBindings:W
Expand Down
Loading