|
@@ -0,0 +1,68 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_chart_lib/models/data_manage/chart_theme"
|
|
|
+ "eta/eta_chart_lib/plugin/basic/shared"
|
|
|
+ "eta/eta_chart_lib/services/data"
|
|
|
+ "github.com/hashicorp/go-hclog"
|
|
|
+ "github.com/hashicorp/go-plugin"
|
|
|
+ "os"
|
|
|
+)
|
|
|
+
|
|
|
+// 实现ChartInterface接口
|
|
|
+type ChartServiceImpl struct {
|
|
|
+ // TODO: add fields
|
|
|
+ logger hclog.Logger
|
|
|
+}
|
|
|
+
|
|
|
+// GetChartData 具体的实现接口逻辑
|
|
|
+func (c *ChartServiceImpl) GetChartData(chartId int) shared.ChartDataResp {
|
|
|
+ c.logger.Info("ChartService.GetChartData", "chartId", chartId)
|
|
|
+ var dataList []int
|
|
|
+ dataList = append(dataList, chartId)
|
|
|
+ resp := shared.ChartDataResp{}
|
|
|
+ resp.DataList = dataList
|
|
|
+ return resp
|
|
|
+}
|
|
|
+
|
|
|
+// GetChartData 具体的实现接口逻辑
|
|
|
+func (c *ChartServiceImpl) GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme chart_theme.ChartTheme, err error) {
|
|
|
+ c.logger.Info("ChartService.GetChartThemeConfig", "chart theme config")
|
|
|
+ chartThemeTmp := new(chart_theme.ChartTheme)
|
|
|
+ chartThemeTmp, err = data.GetChartThemeConfig(chartThemeId, source, chartType)
|
|
|
+ if err != nil {
|
|
|
+ c.logger.Error("ChartService.GetChartThemeConfig", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartTheme = *chartThemeTmp
|
|
|
+ c.logger.Info("ChartService.GetChartThemeConfig", chartTheme.ChartThemeName)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// handshakeConfigs 被用来在插件和宿主(host)之间进行一个基本的握手过程。这个握手过程的主要目的是确保插件与宿主之间的兼容性,并在握手失败时向用户显示一个友好的错误信息。这有助于防止用户执行不兼容的插件或错误地执行一个包含插件的目录。
|
|
|
+// 重要的是要理解,这个握手过程主要是一个用户体验(UX)特性,而不是一个安全特性。它可以帮助用户避免一些常见的错误,但它并不提供严格的安全保障来防止恶意插件的执行。
|
|
|
+// 如果插件的握手配置的MagicCookieKey和MagicCookieValue与宿主期望的值不匹配,握手过程将失败,并且会向用户显示一个错误信息。这有助于防止用户执行不兼容的插件或错误地执行一个包含插件的目录。
|
|
|
+// 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",
|
|
|
+}
|
|
|
+
|
|
|
+func main() {
|
|
|
+ logger := hclog.New(&hclog.LoggerOptions{
|
|
|
+ Level: hclog.Trace,
|
|
|
+ Output: os.Stderr,
|
|
|
+ JSONFormat: true,
|
|
|
+ })
|
|
|
+
|
|
|
+ serverImpl := &ChartServiceImpl{logger: logger}
|
|
|
+ var pluginMap = map[string]plugin.Plugin{
|
|
|
+ "ChartServiceGetData": &shared.ChartPlugin{Impl: serverImpl},
|
|
|
+ }
|
|
|
+
|
|
|
+ plugin.Serve(&plugin.ServeConfig{HandshakeConfig: handshakeConfig, Plugins: pluginMap})
|
|
|
+}
|