You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can do this because genney will replace the string identifier of the file, regardless of its actual type. In this way, we can extend more complex types while being type-safe.
I have summarized several common usages used in my toy project.
Type Object extends to struct (has fields)
typeObjectstruct {
generic.Typenamestringageint
}
// Now you can use it in function without compile errorsfuncdoSomeThing(o*Object) (string, int) {
...returno.name, o.age
}
Type Object extends to interface (has method)
typeObjectinterface {
generic.Type// can be removedrun() Objectstop() Object
}
// use it as normal interfacefuncoperate(oObject) {
o.run().stop()
}
Mock package
// file1: demo.gotypemockPackagestruct {
// package functionLog(...interface{}) error// package exported variableColorRedintColorGreenint// Not find a way to mock exported Type
}
varPackageNamemockPackage// file2: demo_template.go// Use in another filefuncnormalFunc() {
PackageName.Log("Hello", "Good")
color:=PackageName.ColorGreen...
}
// use command// geeny -in=demo_template.go -out=gen_demo.go gen "PackageName=mypkg"
Hi.
Thank you for your providing a neat package!
I would like to extend generic type like this Java example so that I can call method in the
type.
and I find I could do similar stuff with Genny. but it is a bit hacky way.
How about support this use case officially, and add "generic.ignore" for ignoring line?
The text was updated successfully, but these errors were encountered: