Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( ErrUnimplementedSerialize erro.String = "unimplemented Serialize() method" ErrUnimplementedUnserialize erro.String = "unimplemented Unserialize() method" ErrUnexpectedDataInParams erro.StringF = "expected %d callback input parameters, found %d" ErrUnexpectedFuncInParams erro.StringF = "expected %d wrap.Parameter values, found %d" ErrUnexpectedSingleOutParam erro.StringF = "expected a single error return parameter, found %d return parameters" ErrInterfaceNotFound erro.String = "interface not found for serialize" ErrUnknownPanic erro.State = "unknown panic" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorWrap ¶
type ErrorWrap func() error
Example ¶
err := eventCallback()(
// This wraps a function that takes no arguments
// and returns an error
ErrorWrap(func() error {
return fmt.Errorf("sad")
}),
)
fmt.Println("err:", err)
Output: err: sad
func (ErrorWrap) Unserialize ¶
type FuncAnyAck ¶
type FuncAnyAck func(...interface{}) []seri.Serializable
func (FuncAnyAck) Callback ¶
func (fn FuncAnyAck) Callback(v ...interface{}) error
func (FuncAnyAck) CallbackAck ¶
func (fn FuncAnyAck) CallbackAck(v ...interface{}) []interface{}
func (FuncAnyAck) Serialize ¶
func (FuncAnyAck) Serialize() (string, error)
func (FuncAnyAck) Unserialize ¶
func (FuncAnyAck) Unserialize(string) error
type FuncString ¶
type FuncString func(string)
Example ¶
eventCallback("World")(
// This wraps a function that takes a string as an argument and
// and doesn't return
FuncString(func(str string) {
fmt.Println("Hello", str)
}),
)
Output: Hello World
func (FuncString) Callback ¶
func (fn FuncString) Callback(v ...interface{}) error
func (FuncString) Serialize ¶
func (FuncString) Serialize() (string, error)
func (FuncString) Unserialize ¶
func (FuncString) Unserialize(string) error
type Wrap ¶
type Wrap struct {
Func func() interface{} // func([T]...) error
Parameters []seri.Serializable
}
Example ¶
// This can make any function callable without creating the interface
err := eventCallback("Pan", "Wendy")(
// Wrap takes in an object that represents a function
// with parameters and an error output
Wrap{
Parameters: []serialize.Serializable{serialize.StrParam, serialize.StrParam},
Func: func() interface{} {
return func(last, first string) error {
fmt.Println("Peter", last)
fmt.Println(first, "Darling")
return fmt.Errorf("Boys")
}
},
},
)
fmt.Println("The Lost", err)
eventCallback(1, "too", math.Pi, strings.NewReader("FORE"))(
// Wrap takes in an object that represents a function
// with parameters and an error output. Note how the
// output of the function is a function that accepts
// the parameters as arguments.
Wrap{
Parameters: []serialize.Serializable{
serialize.IntParam, serialize.StrParam, serialize.F64Param, serialize.BinParam,
},
Func: func() interface{} {
return func(one int, two string, three float64, four io.Reader) error {
fmt.Println("The number:", one)
fmt.Println("This takes:", two)
fmt.Println("To make my:", three)
fmt.Print("Stream out: ")
_, err := io.Copy(os.Stdout, four)
return err
}
},
},
)
fmt.Println("\n====")
eventCallback(map[string]interface{}{"Got 5 on it": "Luniz & Michael Marshall"})(
// Wrap takes in an object that represents a function
// with parameters and an error output. Note how the
// output of the function is a function that accepts
// the parameters as arguments.
Wrap{
Parameters: []serialize.Serializable{serialize.MapParam},
Func: func() interface{} {
return func(kv map[string]interface{}) error {
for k, v := range kv {
fmt.Printf("%s: %v\n", k, v)
}
return nil
}
},
},
)
Output: Peter Pan Wendy Darling The Lost Boys The number: 1 This takes: too To make my: 3.141592653589793 Stream out: FORE ==== Got 5 on it: Luniz & Michael Marshall
func (Wrap) Unserialize ¶
Click to show internal directories.
Click to hide internal directories.