All Go Backend in Production

Honestly the best way to handle null values is writing simple structs conforming to database/sql.Scanner and database/sql/driver.Valuer:

```golang // NullUint represents a return from a database that uses an uint, where the // uint could possibly be null. type NullUint struct { // Uint is the value that is retrieved / scanned from the database query. Uint uint

// Valid returns true if the value is valid.  This will be false if the
// stored value is null.
Valid bool

}

// Scan implements the Scanner interface. func (nu *NullUint) Scan(value interface{}) error { switch value.(type) { case uint, uint8, uint16, uint32, uint64: nu.Valid = true nu.Uint = value.(uint) return nil case nil: nu.Valid = false nu.Uint = 0 return nil }

return errors.New("Not a valid Uint")

}

// Value implements the driver Valuer interface. func (nu NullUint) Value() (driver.Value, error) { if !nu.Valid { return nil, nil } return nu.Uint, nil } ```

This of course assumes you are using the builtin database/sql packages.

/r/golang Thread Parent