guregu / null

reasonable handling of nullable values
BSD 2-Clause "Simplified" License
1.86k stars 238 forks source link

Strings.StringFrom() passes Valid as true even if the string is empty #56

Closed xfoxawy closed 4 years ago

xfoxawy commented 4 years ago

example

StringFrom("")
``
value

sql.NullString{Value:"", Valid:true}


which is wrong
guregu commented 4 years ago

It’s not wrong, it’s intentional. Use the zero subpackage if you want this kind of behavior.

I noticed the documentation is kind of misleading though, “blank” should be changed to “null”.

xfoxawy commented 4 years ago

should I extract this behavior in new method then?

guregu commented 4 years ago

No need, this behavior is already implemented in this zero subpackage: https://godoc.org/github.com/guregu/null/zero#StringFrom