refactor(zabbix): 使 zabbix agent 插件集成独立化
This commit is contained in:
@ -4,29 +4,21 @@ import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"log"
|
||||
"onvif-agent/constant"
|
||||
"os"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Server serverConfig `mapstructure:"server"`
|
||||
App appConfig `mapstructure:"app"`
|
||||
Integrations integrationConfig `mapstructure:"integrations"`
|
||||
}
|
||||
|
||||
type serverConfig struct {
|
||||
Port int `mapstructure:"port"`
|
||||
Host string `mapstructure:"host"`
|
||||
App appConfig `mapstructure:"app"`
|
||||
}
|
||||
|
||||
type appConfig struct {
|
||||
URL string `mapstructure:"url"`
|
||||
Port int `mapstructure:"port"`
|
||||
Host string `mapstructure:"host"`
|
||||
URL string `mapstructure:"url"` // web server url
|
||||
}
|
||||
|
||||
type integrationConfig struct {
|
||||
ZabbixAgent IntegrationConfig `mapstructure:"zabbix_agent"`
|
||||
}
|
||||
|
||||
var Conf config
|
||||
var Config config
|
||||
|
||||
func LoadConfig() error {
|
||||
env := os.Getenv("PROFILE")
|
||||
@ -37,17 +29,18 @@ func LoadConfig() error {
|
||||
configName = fmt.Sprint("config.", env)
|
||||
}
|
||||
|
||||
log.Println("Loading config: ", configName)
|
||||
|
||||
viper.SetConfigName(configName)
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath(fmt.Sprintf("/etc/%s", constant.AppName))
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := viper.Unmarshal(&Conf); err != nil {
|
||||
log.Println("Loading config file:", viper.ConfigFileUsed())
|
||||
|
||||
if err := viper.Unmarshal(&Config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
package config
|
||||
|
||||
type IntegrationConfig struct {
|
||||
Plugin PluginConfig `mapstructure:"plugin"`
|
||||
}
|
||||
|
||||
type PluginConfig struct {
|
||||
Name string `mapstructure:"name"`
|
||||
Version string `mapstructure:"version"`
|
||||
}
|
Reference in New Issue
Block a user