Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update README to document *bool behavior #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Initialize structs with default values
- Scalar types
- `int/8/16/32/64`, `uint/8/16/32/64`, `float32/64`
- `uintptr`, `bool`, `string`
- `bool` values declared as a `*bool` allow for an unset boolean type. This helps distinguish the case where a default true bool is set to `false`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exclusive to bool values.
Any scalar type can't distinguish an unspecified value from its zero value.
For int, an unspecified value means 0; For string, an empty string ("").

If we want to indicate this behavior in README, we might as well do with technicalities.

- Complex types
- `map`, `slice`, `struct`
- Nested types
Expand Down Expand Up @@ -46,7 +47,7 @@ type Sample struct {
Name string `default:"John Smith"`
Age int `default:"27"`
Gender Gender `default:"m"`
Working bool `default:"true"`
Working *bool `default:"true"`

SliceInt []int `default:"[1, 2, 3]"`
SlicePtr []*int `default:"[1, 2, 3]"`
Expand Down