package main import ( "eta/eta_chart_lib/plugin/basic/shared" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" "log" "os" "os/exec" ) // handshakeConfigs are used to just do a basic handshake between // a plugin and host. If the handshake fails, a user friendly error is shown. // This prevents users from executing bad plugins or executing a plugin // directory. It is a UX feature, not a security feature. var handshakeConfig = plugin.HandshakeConfig{ ProtocolVersion: 1, MagicCookieKey: "BASIC_PLUGIN", MagicCookieValue: "xxyBASIC_PLUGIN", } // pluginMap is the map of plugins we can dispense. var pluginMap = map[string]plugin.Plugin{ "ChartServiceGetData": &shared.ChartPlugin{}, } func main() { // Create an hclog.Logger logger := hclog.New(&hclog.LoggerOptions{ Name: "plugin", Output: os.Stdout, Level: hclog.Debug, }) // We're a host! Start by launching the plugin process. client := plugin.NewClient(&plugin.ClientConfig{ HandshakeConfig: handshakeConfig, Plugins: pluginMap, Cmd: exec.Command("./plugin/chart"), Logger: logger, }) defer client.Kill() // Connect via RPC rpcClient, err := client.Client() if err != nil { log.Fatal(err) } raw, err := rpcClient.Dispense("ChartServiceGetData") if err != nil { log.Fatal(err) } chartData := raw.(shared.ChartInterface) resp := chartData.GetChartData(1) log.Println("Success resp1: ", resp) resp2, err := chartData.GetChartThemeConfig(1, 1, 1) if err != nil { log.Println("Failed resp2: ", err.Error()) log.Fatal(err) } log.Println("Success resp2: ", resp2.ChartThemeName) }