-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: Add an echo plugin for testing the plugin mechanism
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/go-plugin" | ||
|
||
"github.com/jkcfg/jk/pkg/plugin/renderer" | ||
) | ||
|
||
// Echo outputs its input. | ||
type Echo struct { | ||
log hclog.Logger | ||
} | ||
|
||
// Render implements renderer.Renderer. | ||
func (h *Echo) Render(input []byte) ([]byte, error) { | ||
h.log.Debug("debug message from echo plugin") | ||
return input, nil | ||
} | ||
|
||
func main() { | ||
logger := hclog.New(&hclog.LoggerOptions{ | ||
Level: hclog.Info, | ||
Output: os.Stderr, | ||
}) | ||
|
||
r := &Echo{ | ||
log: logger, | ||
} | ||
// pluginMap is the map of plugins we can dispense. | ||
var pluginMap = map[string]plugin.Plugin{ | ||
"renderer": &renderer.Plugin{Impl: r}, | ||
} | ||
|
||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: renderer.RendererV1, | ||
Plugins: pluginMap, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "echo", | ||
"version": "0.1.0", | ||
"binaries": { | ||
"linux-amd64": "jk-plugin-echo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as std from '@jkcfg/std'; | ||
import { render } from '@jkcfg/std/render'; | ||
|
||
render('echo.json', { message: 'success' }).then(r => std.log(r.message)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
success |