Skip to content

Fields without a tag can still change #7

@ansel1

Description

@ansel1

Example:

type Widget struct {
    B []bytes
}

defaults.SetDefaults(&Widget{})

The B field starts out nil, but will be set to an empty byte slice, even though that field has no "default" tag.

Looking at the code, I'm thinking either setDefaultValues should check for the presence of the tag, and skip the field if not present, or setDefaultValue should check the presence of the tag (after the zero value check).

Alternatively, if this was the intended behavior, then perhaps add a default:"-" option to explicitly skip the field? Or a flag in the Filler struct to toggle the behavior? I'd be happy to do a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions