Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interface conversion panic when method is not actually missing

Tags:

go

Somehow, at runtime, I am getting the following panic message, even if it appears to me the method is properly defined to the struct that implements that interface.

panic: interface conversion: schema.MerchantResultset 
is not search.ResultsetInterface: missing method Add

This is the interface blueprint

type ResultsetInterface interface {
    Init(string)
    CacheSet(context.Context) error
    CacheSetPart(context.Context, int) error
    CacheGet(context.Context, string) error
    Add(interface{})
    AddResultset(interface{})
}

The following is the method that is reported missing during runtime, which is assigned to my struct MerchantResultset.

func (mr *MerchantResultset) Add(item interface{}) {
    mr.Data = append(mr.Data, item.(Merchant))
}

I am somehow very puzzled trying to understand what is actually being needed here

like image 403
gextra Avatar asked Apr 10 '16 07:04

gextra


1 Answers

Probably it’s because you are passing around a MerchantResultset, but the Add method is only defined for a pointer to that type.

like image 58
Roland Illig Avatar answered Oct 20 '22 19:10

Roland Illig