wings/internal/models/models.go
Matthew Penner 14ad268af4
go: update dependencies
Signed-off-by: Matthew Penner <me@matthewp.io>
2024-07-24 15:13:04 -06:00

33 lines
505 B
Go

package models
import (
"database/sql"
"encoding/json"
"emperror.dev/errors"
)
type JsonNullString struct {
sql.NullString
}
func (v JsonNullString) MarshalJSON() ([]byte, error) {
if v.Valid {
return json.Marshal(v.String)
} else {
return json.Marshal(nil)
}
}
func (v *JsonNullString) UnmarshalJSON(data []byte) error {
var s *string
if err := json.Unmarshal(data, &s); err != nil {
return errors.WithStack(err)
}
if s != nil {
v.String = *s
}
v.Valid = s != nil
return nil
}