SHARE
TWEET

KarmaDecimal

a guest Oct 18th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type KarmaDecimal struct {
  2.     decimal.Decimal
  3. }
  4.  
  5. // Scan implements the sql.Scanner interface for database deserialization.
  6. func (d *KarmaDecimal) Scan(value interface{}) error {
  7.     // first try to see if the data is stored in database as a Numeric datatype
  8.     switch v := value.(type) {
  9.  
  10.     case float32:
  11.         old_d := decimal.NewFromFloat32(v)
  12.         *d = KarmaDecimal{old_d}
  13.         return nil
  14.     case sql.NullFloat64:
  15.         old_d := decimal.NewFromFloat(v.Float64)
  16.         *d = KarmaDecimal{old_d}
  17.         return nil
  18.     default:
  19.         return d.Decimal.Scan(value)
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top