in codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoValueAccessUtils.java [51:92]
public static void writeIfNonZeroValue(
Model model,
GoWriter writer,
MemberShape member,
String operand,
boolean ignoreEmptyString,
boolean ignoreUnboxedTypes,
Runnable lambda
) {
Shape targetShape = model.expectShape(member.getTarget());
Shape container = model.expectShape(member.getContainer());
// default to empty block for variable scoping with not value check.
String check = "{";
if (GoPointableIndex.of(model).isNillable(member)) {
if (!ignoreEmptyString && targetShape.getType() == ShapeType.STRING) {
check = String.format("if %s != nil && len(*%s) > 0 {", operand, operand);
} else {
check = String.format("if %s != nil {", operand);
}
} else if (container instanceof CollectionShape || container.getType() == ShapeType.MAP) {
if (!ignoreEmptyString && targetShape.getType() == ShapeType.STRING) {
check = String.format("if len(%s) > 0 {", operand);
} else if (!ignoreEmptyString && targetShape.getType() == ShapeType.ENUM) {
check = String.format("if len(%s) > 0 {", operand);
}
} else if (targetShape.hasTrait(EnumTrait.class)) {
check = String.format("if len(%s) > 0 {", operand);
} else if (!ignoreUnboxedTypes && targetShape.getType() == ShapeType.BOOLEAN) {
check = String.format("if %s {", operand);
} else if (!ignoreUnboxedTypes && CodegenUtils.isNumber(targetShape)) {
check = String.format("if %s != 0 {", operand);
} else if (!ignoreEmptyString && targetShape.getType() == ShapeType.STRING) {
check = String.format("if len(%s) > 0 {", operand);
}
writer.openBlock(check, "}", lambda);
}