diff --git a/template/server/conf/config.go b/template/server/conf/config.go new file mode 100644 index 0000000000000000000000000000000000000000..3455125161fe7ef58da63ab090f0fe4964dcf7f5 --- /dev/null +++ b/template/server/conf/config.go @@ -0,0 +1,53 @@ +package conf + +import ( + "flag" + "fmt" + "os" + "path" + + "gitee.com/openeuler/PilotGo-plugin-template/global" + "gitee.com/openeuler/PilotGo/sdk/logger" + "gopkg.in/yaml.v2" +) + +var Global_Config *ServerConfig + +const config_type = "template.yaml" + +var config_dir string + +type ServerConfig struct { + Template *TemplateConf + PilotGo *PilotGoConf + Logopts *logger.LogOpts `yaml:"log"` +} + +func ConfigFile() string { + configfilepath := path.Join(config_dir, config_type) + + return configfilepath +} + +func InitConfig() { + flag.StringVar(&config_dir, "conf", "/opt/PilotGo/plugin/template", "template configuration directory") + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage: %s -conf /path/to/template.yaml(default:/opt/PilotGo/plugin/template) \n", os.Args[0]) + } + flag.Parse() + + bytes, err := global.FileReadBytes(ConfigFile()) + if err != nil { + flag.Usage() + fmt.Printf("open file failed: %s, %s", ConfigFile(), err.Error()) + os.Exit(1) + } + + Global_Config = &ServerConfig{} + + err = yaml.Unmarshal(bytes, Global_Config) + if err != nil { + fmt.Printf("yaml unmarshal failed: %s", err.Error()) + os.Exit(1) + } +} diff --git a/template/server/conf/meta.go b/template/server/conf/meta.go new file mode 100644 index 0000000000000000000000000000000000000000..0c4dc30342b12677f8f6a6e9cbb41465aa8d0ee8 --- /dev/null +++ b/template/server/conf/meta.go @@ -0,0 +1,12 @@ +package conf + +type TemplateConf struct { + Https_enabled bool `yaml:"https_enabled"` + CertFile string `yaml:"cert_file"` + KeyFile string `yaml:"key_file"` + Addr string `yaml:"addr"` +} + +type PilotGoConf struct { + Addr string `yaml:"addr"` +} diff --git a/template/server/template.yml b/template/server/template.yml index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..681de3e665cb92cfeba95df8488da09f080ce4a3 100644 --- a/template/server/template.yml +++ b/template/server/template.yml @@ -0,0 +1,13 @@ +template: + https_enabled: false + 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