Created
June 5, 2013 05:37
-
-
Save bradclawsie/5711821 to your computer and use it in GitHub Desktop.
some "nullable" base types for go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type NullableString string | |
func (n NullableString) MarshalJSON() ([]byte, error) { | |
sn := string(n) | |
if sn == "" { | |
var i interface{} | |
return json.Marshal(i) | |
} | |
return json.Marshal(sn) | |
} | |
type NullableUInt64 uint64 | |
func (n NullableUInt64) MarshalJSON() ([]byte, error) { | |
in := uint64(n) | |
if in == 0 { | |
var i interface{} | |
return json.Marshal(i) | |
} | |
return json.Marshal(in) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment