Skip to content

Plug

The @std/plug module is for loading Go-backed plugins and calling actions on them.

Use plugp when you want Nubo code to communicate with an external Go plugin/backend.

import plug from "@std/plug"
let plugin = plug.require("stdio", "./backend")
let result = plugin.send("hello", {
"name": "Nubo"
})
println(result)
NameKindDescription
PlugstructLoaded Go plugin instance.
requirefunctionLoads a Go plugin and returns a Plug.

Loads a Go plugin/backend and returns a Plug.

Arguments:

NameTypeDefaultDescription
modestring"stdio"Plugin communication mode.
pathstring"./backend"Plugin executable or backend path.
addrstring?nilOptional address.
tokenstring?nilOptional token.

Returns: Plug

import plug from "@std/plug"
let plugin = plug.require("stdio", "./backend")

With a token:

import plug from "@std/plug"
let plugin = plug.require("stdio", "./backend", nil, "secret-token")

Plug represents a loaded Go plugin.

You usually create it with plug.require.

import plug from "@std/plug"
let plugin = plug.require("stdio", "./backend")

Sends an action call to the loaded plugin.

Arguments:

NameTypeDefaultDescription
actionstringnoneAction name to call in the plugin.
propsdict[string, any]?nilOptional payload passed to the action.

Returns: dict[string, any]

import plug from "@std/plug"
let plugin = plug.require("stdio", "./backend")
let response = plugin.send("createUser", {
"name": "Martin",
"admin": true
})
println(response)

Call an action without props by passing nil.

import plug from "@std/plug"
let plugin = plug.require("stdio", "./backend")
let health = plugin.send("health", nil)
println(health)

Function implementations use the return type after the parameter list.

import plugp from "@std/plug"
fn callPlugin(plugin: plug.Plug, action: string) dict[string, any] {
return plugin.send(action, nil)
}