Open adambabik opened 5 years ago
The idea is to implement a custom type and SQL serializer:
type ECDSAPublicKeySQL ecdsa.PublicKey func (k *ECDSAPublicKeySQL) Scan(src interface{}) error { // ... }
The value can be either assigned to Contact like this:
Contact
h.Contact.PublicKey = pubKey.ECDSAPublicKey()
or it can be a separate field and getting the ECDSA Public Key struct will be done through a method:
type Contact struct { publicKey *ECDSAPublicKeySQL } func (c Contact) PublicKey() *ecdsa.PublicKey { pk := ecdsa.PublicKey(*c.publicKey) return &pk } h.Contact.ECDSAPublicKey()
The latter approach is less appealing in this case because for Contact struct we only use fields for now so we end up with collecting some values as fields and one using a method.
The idea is to implement a custom type and SQL serializer:
The value can be either assigned to
Contact
like this:or it can be a separate field and getting the ECDSA Public Key struct will be done through a method:
The latter approach is less appealing in this case because for
Contact
struct we only use fields for now so we end up with collecting some values as fields and one using a method.