private void writeHttpBindingMember()

in codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java [833:909]


    private void writeHttpBindingMember(
            GenerationContext context,
            HttpBinding binding
    ) {
        GoWriter writer = context.getWriter().get();
        Model model = context.getModel();
        MemberShape memberShape = binding.getMember();
        Shape targetShape = model.expectShape(memberShape.getTarget());
        HttpBinding.Location location = binding.getLocation();

        // return an error if member shape targets location label, but is unset.
        if (location.equals(HttpBinding.Location.LABEL)) {
            // labels must always be set to be serialized on URI, and non empty strings,
            GoValueAccessUtils.writeIfZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
                    memberShape, "v", false, true, operand -> {
                        writer.addUseImports(SmithyGoDependency.SMITHY);
                        writer.write("return &smithy.SerializationError { "
                                        + "Err: fmt.Errorf(\"input member $L must not be empty\")}",
                                memberShape.getMemberName());
                    });
        }

        GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
                memberShape, "v", true, memberShape.isRequired(), (operand) -> {
                    final String locationName = binding.getLocationName().isEmpty()
                            ? memberShape.getMemberName() : binding.getLocationName();
                    switch (location) {
                        case HEADER:
                            writer.write("locationName := $S", getCanonicalHeader(locationName));
                            writeHeaderBinding(context, memberShape, operand, location, "locationName", "encoder");
                            break;
                        case PREFIX_HEADERS:
                            MemberShape valueMemberShape = model.expectShape(targetShape.getId(),
                                    MapShape.class).getValue();
                            Shape valueMemberTarget = model.expectShape(valueMemberShape.getTarget());

                            if (targetShape.getType() != ShapeType.MAP) {
                                throw new CodegenException("Unexpected prefix headers target shape "
                                        + valueMemberTarget.getType() + ", "
                                        + valueMemberShape.getId());
                            }

                            writer.write("hv := encoder.Headers($S)", getCanonicalHeader(locationName));
                            writer.addUseImports(SmithyGoDependency.NET_HTTP);
                            writer.openBlock("for mapKey, mapVal := range $L {", "}", operand, () -> {
                                writeHeaderBinding(context, valueMemberShape, "mapVal", location,
                                        "http.CanonicalHeaderKey(mapKey)", "hv");
                            });
                            break;
                        case LABEL:
                            writeHttpBindingSetter(context, writer, memberShape, location, operand, (w, s) -> {
                                w.openBlock("if err := encoder.SetURI($S).$L; err != nil {", "}", locationName, s,
                                        () -> {
                                            w.write("return err");
                                        });
                            });
                            break;
                        case QUERY:
                            writeQueryBinding(context, memberShape, targetShape, operand,
                                    location, locationName, "encoder", false);
                            break;
                        case QUERY_PARAMS:
                            MemberShape queryMapValueMemberShape = CodegenUtils.expectMapShape(targetShape).getValue();
                            Shape queryMapValueTargetShape = model.expectShape(queryMapValueMemberShape.getTarget());
                            MemberShape queryMapKeyMemberShape = CodegenUtils.expectMapShape(targetShape).getKey();
                            writer.openBlock("for qkey, qvalue := range $L {", "}", operand, () -> {
                                writer.write("if encoder.HasQuery(qkey) { continue }");
                                writeQueryBinding(context, queryMapKeyMemberShape, queryMapValueTargetShape,
                                        "qvalue", location, "qkey", "encoder", true);
                            });
                            break;

                        default:
                            throw new CodegenException("unexpected http binding found");
                    }
                });
    }