Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Case ¶
type Case struct { // Method is the method that is invoked when this case is hit. Method reflect.Method // InputMap maps the index of the input parameters passed to Call() to the // index of the method's input parameters. A value of -1 indicates that the // method does not require that parameter. InputMap []int // OutputMap maps the index of the method's output parameters to the index of // the output parameters returned by Call(). A value of -1 indicates that the // method produces a value that is not required. OutputMap []int }
Case represents a single case within a Switch.
type Signature ¶
Signature defines the criteria that must be met for methods to be included in a message set.
func (*Signature) IsMatch ¶
IsMatch returns true if m is a match for s. If it is a match, it returns the concrete implementation of sw that m accepts.
func (*Signature) MapInputs ¶
MapInputs generates a mapping between the types in p and s.In. Any type present in p that is not present in s.In is represented by -1. It returns an error if there are types in s.In that are not present in p.
func (*Signature) MapOutputs ¶
MapOutputs generates a mapping between the types in p and s.Out. Any type present in p that is not present in s.Out is represented by -1. It returns an error if there are types in s.Out that are not present in p.
type Switch ¶
Switch dispatches calls to a method based on the concrete type of some interface value.
func New ¶
func New( in, out []reflect.Type, sigs ...*Signature, ) (Switch, map[*Signature][]reflect.Type, error)
New returns a type-switch that dispatches to methods based on the concrete type of one of the parameters.
in and out are the input and output parameters provided and expected by the caller, respectively. in[0] must be some concrete receiver type, that is the type with the target methods. in[1] must be an interface defining the "switch type", which must be an interface.
sigs is a set of method signatures that define which methods of in[0] (the receiver) will be considered as targets for each switch "case".