codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointDiscoveryGenerator.java
private static void generateAddDiscoverEndpointMiddleware(
            Model model, SymbolProvider symbolProvider, GoWriter writer, ServiceShape service, OperationShape operation
    ) {
        if (!operationUsesEndpointDiscovery(model, service, operation)) {
            return;
        }

        Symbol stackSymbol = SymbolUtils.createPointableSymbolBuilder("Stack", SmithyGoDependency.SMITHY_MIDDLEWARE)
                .build();

        String helperName = generateAddDiscoverEndpointMiddlewareName(service, operation);
        String discoverOperationName = generateFetchDiscoverEndpointFuncName(service, operation);

        // Generate Middleware Adder Helper
        writer.openBlock("func $L(stack $P, o Options, c *Client) error {", "}", helperName, stackSymbol,
                () -> {
                    writer.addUseImports(SmithyGoDependency.SMITHY_MIDDLEWARE);

                    String closeBlock = String.format("}, \"%s\", middleware.After)",
                            EndpointGenerator.MIDDLEWARE_NAME);

                    writer.openBlock("return stack.Serialize.Insert(&$T{", closeBlock, DISCOVERY_MIDDLEWARE, () -> {
                        writer.openBlock("Options: []func($P){", "},", DISCOVERY_ENDPOINT_OPTIONS, () -> {
                            writer.openBlock("func (opt $P) {", "},", DISCOVERY_ENDPOINT_OPTIONS, () -> {
                                writer.write("opt.$L = o.EndpointOptions.$L", DISABLE_HTTPS, DISABLE_HTTPS);
                                writer.write("opt.Logger = o.Logger");

                                if (serviceSupportsCustomDiscoveryEndpoint(model, service)) {
                                    writer.write("opt.$L = o.$L.$L", ENDPOINT_RESOLVER_USED_FOR_DISCOVERY,
                                            ENDPOINT_DISCOVERY_OPTION, ENDPOINT_RESOLVER_USED_FOR_DISCOVERY);
                                }

                            });
                        });
                        writer.write("DiscoverOperation: c.$L,", discoverOperationName);
                        writer.write("EndpointDiscoveryEnableState: o.$L.$L,", ENDPOINT_DISCOVERY_OPTION, ENABLE_ENDPOINT_DISCOVERY_OPTION);
                        writer.write("EndpointDiscoveryRequired: $L,",
                                operationRequiresEndpointDiscovery(model, service, operation));
                    });
                });
        writer.write("");
    }
/**
     * Generates a helper method to add DiscoverEndpoint middleware into the middleware stack.
     *
     * @param model          is the generation model
     * @param symbolProvider is the symbol provider used in generation context
     * @param writer         is the GoWriter
     * @param service        is the service for which endpoint discovery is performed.
     * @param operation      is the operation for which discover endpoint middleware is added.
     */
Generates a helper method to add DiscoverEndpoint middleware into the middleware stack.
@param model          is the generation model
@param symbolProvider is the symbol provider used in generation context
@param writer         is the GoWriter
@param service        is the service for which endpoint discovery is performed.
@param operation      is the operation for which discover endpoint middleware is added.
Generates a helper method to add DiscoverEndpoint middleware into the middleware stack . @param model is the generation model @param symbolProvider is the symbol provider used in generation context @param writer is the GoWriter @param service is the service for which endpoint discovery is performed . @param operation is the operation for which discover endpoint middleware is added .
private static void generateAddDiscoverEndpointMiddleware(
            Model model, SymbolProvider symbolProvider, GoWriter writer, ServiceShape service, OperationShape operation
    ) {
        if (!operationUsesEndpointDiscovery(model, service, operation)) {
            return;
        }
        Symbol stackSymbol = SymbolUtils.createPointableSymbolBuilder("Stack", SmithyGoDependency.SMITHY_MIDDLEWARE)
                .build();
        String helperName = generateAddDiscoverEndpointMiddlewareName(service, operation);
        String discoverOperationName = generateFetchDiscoverEndpointFuncName(service, operation);
        writer.openBlock("func $L(stack $P, o Options, c *Client) error {", "}", helperName, stackSymbol,
                () -> {
                    writer.addUseImports(SmithyGoDependency.SMITHY_MIDDLEWARE);
                    String closeBlock = String.format("}, \"%s\", middleware.After)",
                            EndpointGenerator.MIDDLEWARE_NAME);
                    writer.openBlock("return stack.Serialize.Insert(&$T{", closeBlock, DISCOVERY_MIDDLEWARE, () -> {
                        writer.openBlock("Options: []func($P){", "},", DISCOVERY_ENDPOINT_OPTIONS, () -> {
                            writer.openBlock("func (opt $P) {", "},", DISCOVERY_ENDPOINT_OPTIONS, () -> {
                                writer.write("opt.$L = o.EndpointOptions.$L", DISABLE_HTTPS, DISABLE_HTTPS);
                                writer.write("opt.Logger = o.Logger");
                                if (serviceSupportsCustomDiscoveryEndpoint(model, service)) {
                                    writer.write("opt.$L = o.$L.$L", ENDPOINT_RESOLVER_USED_FOR_DISCOVERY,
                                            ENDPOINT_DISCOVERY_OPTION, ENDPOINT_RESOLVER_USED_FOR_DISCOVERY);
                                }
                            });
                        });
                        writer.write("DiscoverOperation: c.$L,", discoverOperationName);
                        writer.write("EndpointDiscoveryEnableState: o.$L.$L,", ENDPOINT_DISCOVERY_OPTION, ENABLE_ENDPOINT_DISCOVERY_OPTION);
                        writer.write("EndpointDiscoveryRequired: $L,",
                                operationRequiresEndpointDiscovery(model, service, operation));
                    });
                });
        writer.write("");
    }
private static void generateAddDiscoverEndpointMiddleware ( Model model , SymbolProvider symbolProvider , GoWriter writer , ServiceShape service , OperationShape operation ) { if ( ! operationUsesEndpointDiscovery ( model , service , operation ) ) { return ; } Symbol stackSymbol = SymbolUtils . createPointableSymbolBuilder ( "Stack" , SmithyGoDependency . SMITHY_MIDDLEWARE ) . build ( ) ; String helperName = generateAddDiscoverEndpointMiddlewareName ( service , operation ) ; String discoverOperationName = generateFetchDiscoverEndpointFuncName ( service , operation ) ; writer . openBlock ( "func $L(stack $P, o Options, c *Client) error {" , "}" , helperName , stackSymbol , ( ) -> { writer . addUseImports ( SmithyGoDependency . SMITHY_MIDDLEWARE ) ; String closeBlock = String . format ( "}, \"%s\", middleware.After)" , EndpointGenerator . MIDDLEWARE_NAME ) ; writer . openBlock ( "return stack.Serialize.Insert(&$T{" , closeBlock , DISCOVERY_MIDDLEWARE , ( ) -> { writer . openBlock ( "Options: []func($P){" , "}," , DISCOVERY_ENDPOINT_OPTIONS , ( ) -> { writer . openBlock ( "func (opt $P) {" , "}," , DISCOVERY_ENDPOINT_OPTIONS , ( ) -> { writer . write ( "opt.$L = o.EndpointOptions.$L" , DISABLE_HTTPS , DISABLE_HTTPS ) ; writer . write ( "opt.Logger = o.Logger" ) ; if ( serviceSupportsCustomDiscoveryEndpoint ( model , service ) ) { writer . write ( "opt.$L = o.$L.$L" , ENDPOINT_RESOLVER_USED_FOR_DISCOVERY , ENDPOINT_DISCOVERY_OPTION , ENDPOINT_RESOLVER_USED_FOR_DISCOVERY ) ; } } ) ; } ) ; writer . write ( "DiscoverOperation: c.$L," , discoverOperationName ) ; writer . write ( "EndpointDiscoveryEnableState: o.$L.$L," , ENDPOINT_DISCOVERY_OPTION , ENABLE_ENDPOINT_DISCOVERY_OPTION ) ; writer . write ( "EndpointDiscoveryRequired: $L," , operationRequiresEndpointDiscovery ( model , service , operation ) ) ; } ) ; } ) ; writer . write ( "" ) ; }
Generates a helper method to add DiscoverEndpoint middleware into the middleware stack.
Generates a helper method to add DiscoverEndpoint middleware into the middleware stack .
// Generate Middleware Adder Helper