Documentation ¶
Overview ¶
Package callbacks provides a Host Callback router for wapc-go servers.
This package is deprecated and will be removed in a future release.
Use github.com/tarmac-project/wapc-toolkit instead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = fmt.Errorf("callback not found") ErrCanceled = fmt.Errorf("callback context has expired") )
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback struct { // Namespace is the common namespace for this callback, and an example could be "database" or for a specific type of // database, "database:kv". Namespace string // Operation is the function within the namespace to call. For example, a "database:kv" namespace may have a "Get" function. Operation string // Func is the user-provided callback function. This function will execute when the router receives a call with the // specified Namespace and Operation key. Func func([]byte) ([]byte, error) }
Callback is a type that holds the details and function used for callback execution. This type is primarily used internally but also returned from some public methods.
type CallbackResult ¶
type CallbackResult struct { // Namespace is the common namespace for this callback, and an example could be "database" or for a specific type of // database, "database:kv". Namespace string // Operation is the function within the namespace to call. For example, a "database:kv" namespace may have a "Get" function. Operation string // Input is the WASM function supplied input data. Input []byte // Output is the Callback function returned output data. Output []byte // Err is the Callback function returned error. Err error // StartTime provides the time captured at the begging of Callback execution. StartTime time.Time // EndTime provides the time captured at the end of Callback execution. EndTime time.Time }
CallbackResult provides detailed information regarding Callback execution. The callback result is the input to the user-defined PostFunc added in the callback configuration.
type Config ¶
type Config struct { // PreFunc holds a user-defined function called as part of the primary Callback method but before the user-specified callback. // This PreFunc can act as middleware enabling users to restrict access to specific callbacks or perform standard functions with all callbacks. PreFunc func(string, string, []byte) ([]byte, error) // PostFunc is a user-defined function called after the execution of the registered callback function. This PostFunc is // used to enable tracking of callback execution as well as the results of each execution. PostFunc func(CallbackResult) }
Config will configure the Callbacks router and allows users to specify items such as the PreFunc or any router level configurations.
type Router ¶
Router is a callback router, which provides a Callback function that users can register with wapc-go. This callback function will determine which registered callback to execute based on the namespace and function name when invoked.
func New ¶
New will return a Router instance that users can use to register callbacks and provide a generic host callback function.
func (*Router) Callback ¶
func (r *Router) Callback(ctx context.Context, _, namespace, op string, data []byte) ([]byte, error)
Callback is the public callback method, users can register this method as part of a waPC-go module, and when called, it will determine if the received host call has a registered callback or not. If yes, this method will execute the registered Callback; if not, it will return an error indicating the callback method not found.
func (*Router) DelCallback ¶
DelCallback will remove any Callback functions saved for the specified namespace and operation.
func (*Router) RegisterCallback ¶
RegisterCallback will add the provided function into the internal map store of Callbacks, which will enable the Callback method to find and execute the supplied function when appropriate.
Directories ¶
Path | Synopsis |
---|---|
Package httpclient is part of the Tarmac suite of Host Callback packages.
|
Package httpclient is part of the Tarmac suite of Host Callback packages. |
Package kvstore is part of the Tarmac suite of Host Callback packages.
|
Package kvstore is part of the Tarmac suite of Host Callback packages. |
Package logging is part of the Tarmac suite of Host Callback packages.
|
Package logging is part of the Tarmac suite of Host Callback packages. |
Package metrics is part of the Tarmac suite of Host Callback packages.
|
Package metrics is part of the Tarmac suite of Host Callback packages. |
Package database is part of the Tarmac suite of Host Callback packages.
|
Package database is part of the Tarmac suite of Host Callback packages. |