diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java index 6cb56822d6f..453a1fba433 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java @@ -588,13 +588,12 @@ private void writeAwsConfigEndpointResolver(GoWriter writer) { writer.putContext("wrapperHelper", EndpointGenerator.AWS_ENDPOINT_RESOLVER_HELPER); writer.putContext("awsResolver", ENDPOINT_RESOLVER_CONFIG_NAME); writer.putContext("awsResolverWithOptions", AWS_ENDPOINT_RESOLVER_WITH_OPTIONS); - writer.putContext("newResolver", EndpointGenerator.RESOLVER_CONSTRUCTOR_NAME); writer.write(""" func $resolverName:L(cfg aws.Config, o *Options) { if cfg.$awsResolver:L == nil && cfg.$awsResolverWithOptions:L == nil { return } - o.$clientOption:L = $wrapperHelper:L(cfg.$awsResolver:L, cfg.$awsResolverWithOptions:L, $newResolver:L()) + o.$clientOption:L = $wrapperHelper:L(cfg.$awsResolver:L, cfg.$awsResolverWithOptions:L) } """); writer.popState(); diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java index 8a842d55c30..6246a695f97 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java @@ -394,33 +394,26 @@ private void generateAwsEndpointResolverWrapper(GoWriter writer) { writer.write(""" type $T struct { awsResolver $T - resolver $T } - """, wrappedResolverSymbol, endpointResolverWithOptions, resolverInterface); + """, wrappedResolverSymbol, endpointResolverWithOptions); + var endpointNotFoundError = SymbolUtils.createValueSymbolBuilder("EndpointNotFoundError", + AwsGoDependency.AWS_CORE).build(); writeExternalResolveEndpointImplementation(writer, wrappedResolverSymbol, "w", () -> { - var endpointNotFoundError = SymbolUtils.createValueSymbolBuilder("EndpointNotFoundError", - AwsGoDependency.AWS_CORE).build(); - var errorf = SymbolUtils.createValueSymbolBuilder("Errorf", - SmithyGoDependency.FMT).build(); writer.write(""" - if w.awsResolver == nil { - goto fallback - } endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options) if err == nil { return endpoint, nil } - if nf := (&$T{}); !errors.As(err, &nf) { - return endpoint, err + if nf := (&$T{}); errors.As(err, &nf) { + return endpoint, nil } - fallback: - if w.resolver == nil { - return endpoint, $T("default endpoint resolver provided was nil") - } - return w.resolver.ResolveEndpoint(region, options)""", endpointNotFoundError, errorf); + return endpoint, err + + + """, endpointNotFoundError); writer.addUseImports(SmithyGoDependency.ERRORS); }); @@ -441,28 +434,30 @@ private void generateAwsEndpointResolverWrapper(GoWriter writer) { // Generate exported helper for constructing a wrapper around the AWS EndpointResolver type that is compatible // with the clients EndpointResolver interface. writer.write(""" - // $L returns an EndpointResolver that first delegates endpoint resolution to the awsResolver. - // If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided - // fallbackResolver for resolution. + // $1L returns an $3T that first delegates endpoint resolution to the awsResolver. + // If awsResolver returns $7T error, the resolver will swallow the error, such + // that fallback will occur when $8L is invoked via its middleware. // - // fallbackResolver must not be nil - func $L(awsResolver $T, awsResolverWithOptions $T, fallbackResolver $T) $T { - var resolver $T + // If another error (besides $7T) is returned, then that error will be propagated. + func $1L(awsResolver $2T, awsResolverWithOptions $3T) $6L { + var resolver $3T if awsResolverWithOptions != nil { resolver = awsResolverWithOptions } else if awsResolver != nil { - resolver = $L(awsResolver.ResolveEndpoint) + resolver = $4L(awsResolver.ResolveEndpoint) } - return &$T{ + return &$5T{ awsResolver: resolver, - resolver: fallbackResolver, } } - """, AWS_ENDPOINT_RESOLVER_HELPER, AWS_ENDPOINT_RESOLVER_HELPER, - endpointResolver, endpointResolverWithOptions, resolverInterface, - resolverInterface, endpointResolverWithOptions, AWS_ENDPOINT_RESOLVER_ADAPTOR, wrappedResolverSymbol); + """, AWS_ENDPOINT_RESOLVER_HELPER, + endpointResolver, endpointResolverWithOptions, + AWS_ENDPOINT_RESOLVER_ADAPTOR, wrappedResolverSymbol, + resolverInterface, endpointNotFoundError, + EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME + ); } private void generateMiddleware(GoWriter writer) {