Skip to content

(aws.String).ValueOrZero() etc. #124

Closed
@mitchellh

Description

@mitchellh

Hello! We've discussed before whether the pointer wrappers are going to continue to exist or not, but in the case they do, I have another request.

Currently, in Terraform, we have to do this a LOT:

if awsGoObject.StringPointer == nil {
    d.Set("thing", "")
} else {
    d.Set("thing". *awsGoObject.StringPointer)
}

It would be very helpful if there was a function called ValueOrZero (the function name we usually use in situations like this). We could write one for every AWS type, but I feel this would be generally useful. The implementation would be something like this for every type:

func (ptr String) ValueOrZero() string {
    if ptr == nil {
        return ""
    }

    return *ptr
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-reviewThis issue or pull request needs review from a core team member.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions