This question already has an answer here:
I am trying to run this code:
type NullInt64 struct {
sql.NullInt64
}
func ToNullInt64(s string) NullInt64 {
i, err := strconv.Atoi(s)
return NullInt64{Int64: int64(i), Valid: err == nil}
}
but I get this error:
..\sql\sql.go:27: unknown NullInt64 field 'Int64' in struct literal
..\sql\sql.go:27: unknown NullInt64 field 'Valid' in struct literal
</div>
To initialize the embedded sql.NullInt64, you have to write:
NullInt64{sql.NullInt64{Int64: int64(i), Valid: err == nil}}
or, if your NullInt64 struct contains other fields which you don't want to initialize explicitly, you can access the embedded field by using its type:
NullInt64{NullInt64: sql.NullInt64{Int64: int64(i), Valid: err == nil}}