Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PropogateInterfaces ¶
func PropogateInterfaces( pkg *packages.Package, wrapperFuncName string, structSelector string, wrappedInterfaces []string, ) (string, error)
PropogateInterfaces wraps the given interface in the given package to allow also implementing a named set of additional interfaces iff the given wrappingInterface also implements them, as determined at runtime.
Let's consider a simple concrete example: Assume we have a package with the following struct:
type foo struct { io.Reader }
Calling:
PropogateInterfaces(pkg, "propagateReader", "f *foo.Reader", []string{"io.Closer"})
Which will generate code for:
func (f *foo) propagateReader() io.Reader { // returns a type that implements 'io.Closer' iff f.Reader implements 'io.Closer' }
Why is this ever useful? See https://medium.com/@cep21/interface-wrapping-method-erasure-c523b3549912
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.