30 lines
417 B
Go
30 lines
417 B
Go
package model
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
)
|
|
|
|
type NullableInt64 struct {
|
|
Set bool
|
|
Valid bool
|
|
Value int64
|
|
}
|
|
|
|
func (n *NullableInt64) UnmarshalJSON(data []byte) error {
|
|
n.Set = true
|
|
if bytes.Equal(data, []byte("null")) {
|
|
n.Valid = false
|
|
n.Value = 0
|
|
return nil
|
|
}
|
|
|
|
var value int64
|
|
if err := json.Unmarshal(data, &value); err != nil {
|
|
return err
|
|
}
|
|
n.Valid = true
|
|
n.Value = value
|
|
return nil
|
|
}
|