mirror of
https://github.com/mudler/luet.git
synced 2025-07-11 14:23:10 +00:00
.. | ||
events.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
manager.go | ||
plugin.go | ||
README.md |
🍱 go-pluggable
🍱 go-pluggable is a light Bus-event driven plugin library for Golang.
go-pluggable
implements the event/sub pattern to extend your Golang project with external binary plugins that can be written in any language.
import "github.com/mudler/go-pluggable"
func main() {
var myEv pluggableEventType = "something.to.hook.on"
temp := "/usr/custom/bin"
m = pluggable.NewManager(
[]pluggable.EventType{
myEv,
},
)
// We have a file 'test-foo' in temp.
// 'test-foo' will receive our event payload in json
m.Autoload("test", temp)
m.Register()
// Optionally process plugin results response
// The plugins has to return as output a json in stdout in the format { 'state': "somestate", data: "some data", error: "some error" }
// e.g. with jq:
// jq --arg key0 'state' \
// --arg value0 '' \
// --arg key1 'data' \
// --arg value1 "" \
// --arg key2 'error' \
// --arg value2 '' \
// '. | .[$key0]=$value0 | .[$key1]=$value1 | .[$key2]=$value2' \
// <<<'{}'
m.Response(myEv, func(p *pluggable.Plugin, r *pluggable.EventResponse) { ... })
// Emit events, they are encoded and passed as JSON payloads to the plugins.
// In our case, test-foo will receive the map as JSON
m.Publish(myEv, map[string]string{"foo": "bar"})
}