diff options
author | Chris <ccbrown112@gmail.com> | 2017-08-16 17:23:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-16 17:23:38 -0500 |
commit | f80d50adbddf55a043dfcab5b47d7c1e22749b7d (patch) | |
tree | 5deb606debb6322716c9cdcc6c58be4f68b74223 /plugin/rpcplugin/main.go | |
parent | 4f85ed985d478ddf6692fa4f7d8d98d2a412d18c (diff) | |
download | chat-f80d50adbddf55a043dfcab5b47d7c1e22749b7d.tar.gz chat-f80d50adbddf55a043dfcab5b47d7c1e22749b7d.tar.bz2 chat-f80d50adbddf55a043dfcab5b47d7c1e22749b7d.zip |
PLT-7407: Back-end plugin mechanism (#7177)
* begin backend plugin wip
* flesh out rpcplugin. everything done except for minor supervisor stubs
* done with basic plugin infrastructure
* simplify tests
* remove unused test lines
Diffstat (limited to 'plugin/rpcplugin/main.go')
-rw-r--r-- | plugin/rpcplugin/main.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plugin/rpcplugin/main.go b/plugin/rpcplugin/main.go new file mode 100644 index 000000000..36177954b --- /dev/null +++ b/plugin/rpcplugin/main.go @@ -0,0 +1,46 @@ +package rpcplugin + +import ( + "bufio" + "encoding/binary" + "fmt" + "log" + "os" + + "github.com/mattermost/platform/plugin" +) + +// Makes a set of hooks available via RPC. This function never returns. +func Main(hooks plugin.Hooks) { + ipc, err := InheritedProcessIPC() + if err != nil { + log.Fatal(err.Error()) + } + muxer := NewMuxer(ipc, true) + id, conn := muxer.Serve() + buf := make([]byte, 11) + buf[0] = 0 + n := binary.PutVarint(buf[1:], id) + if _, err := muxer.Write(buf[:1+n]); err != nil { + log.Fatal(err.Error()) + } + ServeHooks(hooks, conn, muxer) + os.Exit(0) +} + +// Returns the hooks being served by a call to Main. +func ConnectMain(muxer *Muxer) (*RemoteHooks, error) { + buf := make([]byte, 1) + if _, err := muxer.Read(buf); err != nil { + return nil, err + } else if buf[0] != 0 { + return nil, fmt.Errorf("unexpected control byte") + } + reader := bufio.NewReader(muxer) + id, err := binary.ReadVarint(reader) + if err != nil { + return nil, err + } + + return ConnectHooks(muxer.Connect(id), muxer), nil +} |