There was an error while loading. Please reload this page.
After setting up a Dispatch endpoint, the next step is to define and register a function.
Dispatch functions have the form:
func (ctx context.Context, input I) (output O, err error)
I and O are any type that Dispatch can serialize:
I
O
encoding.BinaryMarshaler
encoding.TextMarshaler
json.Marshaler
proto.Message
Functions are defined using the dispatch.Func helper.
dispatch.Func
Here's an example function that converts an integer to a string:
stringify := dispatch.Func("stringify", func (ctx context.Context, input int) (string, error) { return strconv.Itoa(input), nil })
Functions can be registered with a Dispatch endpoint when the endpoint is created.
For example, to register the stringify function defined above:
stringify
endpoint, err := dispatch.New(stringify)
Alternatively, functions can be registered after an endpoint has been created:
endpoint.Register(stringify)
See how to call a function.