diff --git a/template/server/conf/config.go b/template/server/conf/config.go index 3455125161fe7ef58da63ab090f0fe4964dcf7f5..008aa534aad3d8daa7185bc7c68f8efd7270ae90 100644 --- a/template/server/conf/config.go +++ b/template/server/conf/config.go @@ -19,8 +19,8 @@ var config_dir string type ServerConfig struct { Template *TemplateConf - PilotGo *PilotGoConf Logopts *logger.LogOpts `yaml:"log"` + Etcd *Etcd `yaml:"etcd" mapstructure:"etcd"` } func ConfigFile() string { diff --git a/template/server/conf/meta.go b/template/server/conf/meta.go index 0c4dc30342b12677f8f6a6e9cbb41465aa8d0ee8..ad9015e26b3a0ba75612d426d285cf583e1b8e04 100644 --- a/template/server/conf/meta.go +++ b/template/server/conf/meta.go @@ -1,5 +1,7 @@ package conf +import "time" + type TemplateConf struct { Https_enabled bool `yaml:"https_enabled"` CertFile string `yaml:"cert_file"` @@ -7,6 +9,11 @@ type TemplateConf struct { Addr string `yaml:"addr"` } -type PilotGoConf struct { - Addr string `yaml:"addr"` +type Etcd struct { + Endpoints []string `yaml:"endpoints"` + ServiveName string `yaml:"service_name"` + Version string `yaml:"version"` + DialTimeout time.Duration `yaml:"dialTimeout"` + MenuName string `yaml:"menu_name"` + Icon string `yaml:"icon"` } diff --git a/template/server/pluginclient/meta.go b/template/server/pluginclient/meta.go deleted file mode 100644 index cc0f9b9d99a3847823b803f19384ea712785e67d..0000000000000000000000000000000000000000 --- a/template/server/pluginclient/meta.go +++ /dev/null @@ -1,15 +0,0 @@ -package pluginclient - -import "gitee.com/openeuler/PilotGo/sdk/plugin/client" - -const Version = "1.0.1" - -var PluginInfo = &client.PluginInfo{ - Name: "template", - Version: Version, - Description: "template plugin for PilotGo", - Author: "", - Email: "", - Url: "", // 插件服务端地址,非插件配置文件中web服务器的监听地址 - PluginType: "micro-app", -} diff --git a/template/server/pluginclient/pluginClient.go b/template/server/pluginclient/pluginClient.go index d89c3c848660774d0ada5e336b0ad81434213f77..76a8f5c5738b7389002bbad3aec92b3c53f977b5 100644 --- a/template/server/pluginclient/pluginClient.go +++ b/template/server/pluginclient/pluginClient.go @@ -2,8 +2,12 @@ package pluginclient import ( "context" + "os" + "gitee.com/openeuler/PilotGo-plugin-template/conf" "gitee.com/openeuler/PilotGo/sdk/common" + "gitee.com/openeuler/PilotGo/sdk/go-micro/registry" + "gitee.com/openeuler/PilotGo/sdk/logger" "gitee.com/openeuler/PilotGo/sdk/plugin/client" ) @@ -12,9 +16,32 @@ var Global_Client *client.Client var Global_Context context.Context func InitPluginClient() { - Global_Client = client.DefaultClient(PluginInfo) + sr, err := registry.NewServiceRegistrar(®istry.Options{ + Endpoints: conf.Global_Config.Etcd.Endpoints, + ServiceAddr: conf.Global_Config.Template.Addr, + ServiceName: conf.Global_Config.Etcd.ServiveName, + Version: conf.Global_Config.Etcd.Version, + MenuName: conf.Global_Config.Etcd.MenuName, + Icon: conf.Global_Config.Etcd.Icon, + DialTimeout: conf.Global_Config.Etcd.DialTimeout, + Extentions: GetExtentions(), + Permissions: GetPermissions(), + }) + if err != nil { + logger.Error("failed to initialize registry: %s", err) + os.Exit(-1) + } - // 注册插件扩展点 + client, err := client.NewClient(conf.Global_Config.Etcd.ServiveName, sr.Registry) + if err != nil { + logger.Error("failed to create plugin client: %s", err) + os.Exit(-1) + } + Global_Client = client + Global_Context = context.Background() +} + +func GetExtentions() []common.Extention { var ex []common.Extention pe1 := &common.PageExtention{ Type: common.ExtentionPage, @@ -35,7 +62,10 @@ func InitPluginClient() { Permission: "plugin.template/function", } ex = append(ex, pe1, me2, be3) - Global_Client.RegisterExtention(ex) + return ex +} - Global_Context = context.Background() +func GetPermissions() []common.Permission { + var pe []common.Permission + return pe } diff --git a/template/server/template.yaml.template b/template/server/template.yaml.template index 681de3e665cb92cfeba95df8488da09f080ce4a3..aa8cd1e43e26576e230005ed90c955540bb11698 100644 --- a/template/server/template.yaml.template +++ b/template/server/template.yaml.template @@ -3,11 +3,17 @@ template: cert_file: "" key_file: "" addr: "0.0.0.0:49151" -PilotGo: - addr: "localhost:8888" log: level: debug driver: file # 可选stdout和file。stdout:输出到终端控制台;file:输出到path下的指定文件。 path: /opt/PilotGo/plugin/elk/log/elk.log max_file: 1 - max_size: 10485760 \ No newline at end of file + max_size: 10485760 +etcd: + endpoints: + - "localhost:2379" + service_name: "template-service" + version: "3.0" + dialTimeout: 5s + menu_name: "模板" + icon: "Odometer" \ No newline at end of file