I want to override the Stringer interface for all instances sql.NullString so that the output of an instance is instance.String rather than { instance.String, instance.Valid }.
The normal way of doing this is to provide a Stringer interface. With sql.NullString a Stringer interface method fails to compile as there is already a String field.
The workaround is to just use instance.String everywhere.
type NullString sql.NullString
// this fails to compile as sql.NullString has a field named String
func (x *NullString) String() string {
if !x.Valid {
x.String = ""
}
return x.String
}
How can a Stinger interface be created if a struct already, like sql.NullString, has a String field?
type NullString sql.NullString"loses" theScanandValuemethods, therefore an instance of your NullString will lose its purpose.