简体   繁体   English

当方法实际上没有丢失时,界面转换恐慌

[英]interface conversion panic when method is not actually missing

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. 以下是在运行时报告丢失的方法,该方法分配给我的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 我在某种程度上非常困惑,试图了解这里实际需要什么

可能是因为您传递的是MerchantResultset ,但Add方法仅针对指向该类型的指针定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 恐慌:接口转换:* 不是接口 X:缺少方法 xxx - Panic: interface conversion: * is not inteface X: missing method xxx Golang杜松子酒-gonic反向代理导致恐慌“接口转换:* http.timeoutWriter不是http.CloseNotifier:缺少方法CloseNotify” - Golang gin-gonic reverse proxying leads to panic “interface conversion: *http.timeoutWriter is not http.CloseNotifier: missing method CloseNotify” Golang panic:接口转换:interface {} is nil, not string - Golang panic: interface conversion: interface {} is nil, not string Golang接口转换错误:缺少方法 - Golang interface conversion error: missing method 前往:来自BST和界面转换的紧急错误 - Go : panic errors from BST and interface conversion 恐慌:接口转换:接口 {} 是字符串,而不是 float64 - panic: interface conversion: interface {} is string, not float64 恐慌接口转换接口 {} 是 float64 而不是 int64 - panic interface conversion interface {} is float64 not int64 Go build 命令抛出 - panic: interface conversion: interface {} is []uint8, not *validator.FieldValidator - Go build command throws - panic: interface conversion: interface {} is []uint8, not *validator.FieldValidator Gin 反向代理测试因接口转换失败:*httptest.ResponseRecorder is not http.CloseNotifier:缺少方法 CloseNotify - Gin reverse proxy tests failing for interface conversion: *httptest.ResponseRecorder is not http.CloseNotifier: missing method CloseNotify 为什么当我输入 assert 接口时我的代码会发生恐慌? - Why does my code panic when I type assert an interface?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM