Skip to content

Commit 0ece687

Browse files
committed
plugins: Add an echo plugin for testing the plugin mechanism
1 parent 7b84539 commit 0ece687

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

plugins/jk-plugin-echo/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/hashicorp/go-hclog"
7+
"github.com/hashicorp/go-plugin"
8+
9+
"github.com/jkcfg/jk/pkg/plugin/renderer"
10+
)
11+
12+
// Echo outputs its input.
13+
type Echo struct {
14+
log hclog.Logger
15+
}
16+
17+
// Render implements renderer.Renderer.
18+
func (h *Echo) Render(input []byte) ([]byte, error) {
19+
h.log.Debug("debug message from echo plugin")
20+
return input, nil
21+
}
22+
23+
func main() {
24+
logger := hclog.New(&hclog.LoggerOptions{
25+
Level: hclog.Info,
26+
Output: os.Stderr,
27+
})
28+
29+
r := &Echo{
30+
log: logger,
31+
}
32+
// pluginMap is the map of plugins we can dispense.
33+
var pluginMap = map[string]plugin.Plugin{
34+
"renderer": &renderer.Plugin{Impl: r},
35+
}
36+
37+
plugin.Serve(&plugin.ServeConfig{
38+
HandshakeConfig: renderer.RendererV1,
39+
Plugins: pluginMap,
40+
})
41+
}

tests/echo.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "echo",
3+
"version": "0.1.0",
4+
"binaries": {
5+
"linux-amd64": "jk-plugin-echo",
6+
"darwin-amd64": "jk-plugin-echo"
7+
}
8+
}

tests/test-plugin-echo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as std from '@jkcfg/std';
2+
import { render } from '@jkcfg/std/render';
3+
4+
render('echo.json', { message: 'success' }).then(r => std.log(r.message));

tests/test-plugin-echo.js.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
success

0 commit comments

Comments
 (0)