add IsZero()
Go 1.4 will have JSON ,omitempty respect this, maybe.
This commit is contained in:
parent
cf649e8f2a
commit
95bde34e57
2 changed files with 17 additions and 0 deletions
|
@ -45,3 +45,8 @@ func (s String) Pointer() *string {
|
|||
}
|
||||
return &s.String
|
||||
}
|
||||
|
||||
// IsZero returns true for invalid strings, for future omitempty support (Go 1.4?)
|
||||
func (s String) IsZero() bool {
|
||||
return !s.Valid
|
||||
}
|
||||
|
|
|
@ -63,6 +63,18 @@ func TestPointer(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIsZero(t *testing.T) {
|
||||
str := StringFrom("test")
|
||||
if str.IsZero() {
|
||||
t.Errorf("IsZero() should be false")
|
||||
}
|
||||
|
||||
null := StringFrom("")
|
||||
if !null.IsZero() {
|
||||
t.Errorf("IsZero() should be true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
var str String
|
||||
err := str.Scan("test")
|
||||
|
|
Loading…
Reference in a new issue