luet/vendor/github.com/mudler/go-pluggable
2021-05-13 18:13:44 +02:00
..
events.go Update go-pluggable 2021-05-13 18:13:44 +02:00
go.mod Update go-pluggable 2021-05-11 14:02:15 +02:00
go.sum Update go-pluggable 2021-05-11 14:02:15 +02:00
LICENSE Update go-pluggable 2020-11-13 19:50:10 +01:00
manager.go Update go-pluggable 2021-05-11 14:02:15 +02:00
plugin.go Update go-pluggable 2021-05-13 18:13:44 +02:00
README.md Update go-pluggable 2021-05-11 14:02:15 +02:00

🍱 go-pluggable

PkgGoDev Go Report Card Test

🍱 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"})


}