From f8a04994d880cdd50585066d644a025308ea0235 Mon Sep 17 00:00:00 2001 From: hbc Date: Fri, 4 Aug 2023 18:32:21 +0800 Subject: [PATCH 1/2] fix: register type with prefix --- mockgen/model/model.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mockgen/model/model.go b/mockgen/model/model.go index 398ffef..55324f9 100644 --- a/mockgen/model/model.go +++ b/mockgen/model/model.go @@ -147,12 +147,12 @@ type Type interface { } func init() { - gob.Register(&ArrayType{}) - gob.Register(&ChanType{}) - gob.Register(&FuncType{}) - gob.Register(&MapType{}) - gob.Register(&NamedType{}) - gob.Register(&PointerType{}) + gob.RegisterName(pkgPath+".ArrayType", &ArrayType{}) + gob.RegisterName(pkgPath+".ChanType", &ChanType{}) + gob.RegisterName(pkgPath+".FuncType", &FuncType{}) + gob.RegisterName(pkgPath+".MapType", &MapType{}) + gob.RegisterName(pkgPath+".NamedType", &NamedType{}) + gob.RegisterName(pkgPath+".PointerType", &PointerType{}) // Call gob.RegisterName to make sure it has the consistent name registered // for both gob decoder and encoder. From fc1f71756ce9d38644d1687812bf8541f56cb409 Mon Sep 17 00:00:00 2001 From: hbc Date: Sat, 12 Aug 2023 14:04:21 +0800 Subject: [PATCH 2/2] doc: call out why we need pkgPath prefix --- mockgen/model/model.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mockgen/model/model.go b/mockgen/model/model.go index 55324f9..e2dde53 100644 --- a/mockgen/model/model.go +++ b/mockgen/model/model.go @@ -147,6 +147,8 @@ type Type interface { } func init() { + // Call gob.RegisterName with pkgPath as prefix to avoid conflicting with + // github.com/golang/mock/mockgen/model 's registration. gob.RegisterName(pkgPath+".ArrayType", &ArrayType{}) gob.RegisterName(pkgPath+".ChanType", &ChanType{}) gob.RegisterName(pkgPath+".FuncType", &FuncType{})