// Scan implements the database/sql Scanner interface. It will receive a value
// from an SQL database and assign it to b, so long as the provided data can be
// is a []byte, a string, or nil. Valid data is expected to be base64 encoded.
Scan implements the database/sql Scanner interface. It will receive a value
from an SQL database and assign it to b, so long as the provided data can be
is a []byte, a string, or nil. Valid data is expected to be base64 encoded.
// Scan implements the database / sql Scanner interface . It will receive a value // from an SQL database and assign it to b so long as the provided data can be // is a [] byte a string or nil . Valid data is expected to be base64 encoded .
func (b *ByteSlice) Scan(src interface{}) error {
	if b == nil {
		return fmt.Errorf("null.ByteSlice: Scan called on nil pointer")
	}
	switch val := src.(type) {
	case nil:
		b.ByteSlice = nil
		b.Valid = false
		return nil
	case []byte:
		if val == nil {
			b.ByteSlice = nil
			b.Valid = false
			return nil
		}
		tmp := make([]byte, base64.StdEncoding.DecodedLen(len(val)))
		n, err := base64.StdEncoding.Decode(tmp, val)
		if err != nil {
			return err
		}
		b.ByteSlice = tmp[:n]
		b.Valid = true
		return nil
	case string:
		tmp, err := base64.StdEncoding.DecodeString(val)
		if err != nil {
			return err
		}
		b.ByteSlice = tmp
		b.Valid = true
		return nil
	default:
		return fmt.Errorf("null.ByteSlice: cannot scan type %T (%v)",
			val, src)
	}
}
func ( b * ByteSlice ) Scan ( src interface { } ) error { if b == nil { return fmt . Errorf ( " " ) } switch val := src . ( type ) { case nil : b . ByteSlice = nil b . Valid = false return nil case [ ] byte : if val == nil { b . ByteSlice = nil b . Valid = false return nil } tmp := make ( [ ] byte , base64 . StdEncoding . DecodedLen ( len ( val ) ) ) n , err := base64 . StdEncoding . Decode ( tmp , val ) if err != nil { return err } b . ByteSlice = tmp [ : n ] b . Valid = true return nil case string : tmp , err := base64 . StdEncoding . DecodeString ( val ) if err != nil { return err } b . ByteSlice = tmp b . Valid = true return nil default : return fmt . Errorf ( " " , val , src ) } }
Scan implements the database/sql Scanner interface.
Scan implements the database / sql Scanner interface .