Last active
October 22, 2019 08:22
-
-
Save anta40/0fab5c0626433a6c376b6e0f6df38ba0 to your computer and use it in GitHub Desktop.
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 NullString struct { | |
sql.NullString | |
} | |
type NullTime struct { | |
sql.NullString | |
} | |
func (ns *NullString) MarshalJSON() ([]byte, error) { | |
if !ns.Valid { | |
return []byte("null"), nil | |
} | |
return json.Marshal(ns.String) | |
} | |
func (nt *NullTime) MarshalJSON() ([]byte, error) { | |
if !nt.Valid { | |
return []byte("null"), nil | |
} | |
t, err := time.Parse("3 04 PM", nt.String) | |
if err != nil { | |
fmt.Println(err) | |
} | |
return json.Marshal(t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment