问题出现方式:接口赋值没有使用 &
type Service interface {
Identify(ctx context.Context, Data []byte) (int, error)
}
type VadService struct{}
func (s *VadService) Identify(ctx context.Context, Data []byte) (int, error) {
return 0,nil;
}
func test(){
// 此处会报错, Identify method has pointer receiver
var svc Service = VadService{}
// 接口类型转换
var svc1 Service
// 此处会报错:Identify method has pointer receiver
svc1 = svc1.(VadService)
}
处理: 加上&,或*
func test(){
var svc Service = &VadService{}
var svc1 Service
svc1 = svc1.(*VadService)
}