I have created a type Role based off string, and I am now trying to get it to work with the database driver by implementing the Valuer and Scanner interfaces
Here is working code for the first function:
func (r *Role) Scan(value interface{}) error {
*r = Role(value.(string))
return nil
}
Although you may wish to use s, ok := value.(string) and return an error for !ok instead of panic-ing.
The signature for the a driver.Valuer is not what you gave but:
func (r Role) Value() (driver.Value, error) {
return string(r), nil
}
Note this doesn't handle or produce NULL values.
Playground