Comments (4)
I've reproduced in a draft PR the ultimate issue: a person cannot set a false
value on a boolean field that has a default of true
. @fchikwekwe and I were able to sort of work around this by flubbing the default:
tag annotation syntax.
from defaults.
Updated the PR to demonstrate that a bool pointer is necessary to be able to have a boolean field that defaults to true
and still be able for a user to set the field to false
. If this is the only or best way to accomplish default-true booleans, we can open a new PR or update the existing one to not add tests but instead update the README documentation to warn users about defaulting a bool
field to true
and recommend using a *bool
.
from defaults.
The scope of this issue is now to document the boolean pointer workaround in the README. I'll open a PR for that and link it shortly.
from defaults.
Then I discover #15 and #30 which describe the same situation. In addition to documenting "bool fields set to default:'true' will not behave how you might think!" would it be helpful for the library to warn or error when setting a field of type bool
whose default is true
?
from defaults.
Related Issues (20)
- Wrong example in Readme? HOT 1
- Default value for slice of struct doesn't work for golang v 1.12 HOT 2
- Default true on bool does not allow to set false HOT 1
- The Setter interface only works on struct pointer fields, not the struct itself
- bug: not set default for fields of a pointer struct field in an object.
- Add MustSet() function HOT 1
- Default values map[string][]string for struct HOT 2
- Default value to the entry that key already exists in a map HOT 5
- Booleans and defaults seems not to be working HOT 2
- Unable to keep zero value in case of setting the zero value on purpose HOT 2
- Customizable value filler
- Add require field tag
- bool is false default is true, handler is true HOT 1
- bug: []time.Duration not works HOT 5
- Support unmarshalling custom types.
- Unset() HOT 1
- Panic when attempting to initialize a field which references an interface HOT 1
- no errors if default value doesn't parse HOT 1
- How to support slice of struct? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defaults.