I want to create a function on the sql.Row
struct that scans a row into my struct ErrorModel
. This is what I am doing:
func (row *sql.Row) ScanErrorModel(mod *model.ErrorModel, err error) {
err = row.Scan(&mod.MessageId, &mod.ServiceName, &mod.EventName,
&mod.Hostname, &mod.Message, &mod.CriticalRate, &mod.Extra, &mod.Timestamp)
return
}
func (dao *ErrorsDAO) Fetch(id string) (mod *model.ErrorModel, err error) {
row := dao.DB.QueryRow("select * from errors where message_id=$1", id)
return row.ScanErrorModel()
}
But I am getting a compiler error here:
row.ScanErrorModel undefined (type *sql.Row has no field or method ScanErrorModel)
Is it impossible to add a function onto a struct that is defined somewhere else like this? Or am I just making a syntax error?