mirror of https://github.com/statping/statping
36 lines
695 B
Go
36 lines
695 B
Go
![]() |
package null
|
||
|
|
||
|
import "encoding/json"
|
||
|
|
||
|
// MarshalJSON for NullInt64
|
||
|
func (ni NullInt64) MarshalJSON() ([]byte, error) {
|
||
|
if !ni.Valid {
|
||
|
return []byte("null"), nil
|
||
|
}
|
||
|
return json.Marshal(ni.Int64)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON for NullFloat64
|
||
|
func (ni NullFloat64) MarshalJSON() ([]byte, error) {
|
||
|
if !ni.Valid {
|
||
|
return []byte("null"), nil
|
||
|
}
|
||
|
return json.Marshal(ni.Float64)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON for NullBool
|
||
|
func (nb NullBool) MarshalJSON() ([]byte, error) {
|
||
|
if !nb.Valid {
|
||
|
return []byte("null"), nil
|
||
|
}
|
||
|
return json.Marshal(nb.Bool)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON for NullString
|
||
|
func (ns NullString) MarshalJSON() ([]byte, error) {
|
||
|
if !ns.Valid {
|
||
|
return []byte("null"), nil
|
||
|
}
|
||
|
return json.Marshal(ns.String)
|
||
|
}
|