1
0

merge: 合并代码

This commit is contained in:
TsMask
2024-04-30 20:37:27 +08:00
parent 78bd110b03
commit 3cc193f57d
95 changed files with 3028 additions and 1519 deletions

View File

@@ -11,16 +11,6 @@ import (
"gopkg.in/yaml.v3"
)
type DbConfig struct {
Type string `yaml:"type"`
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Name string `yaml:"name"`
Backup string `yaml:"backup"`
}
// Yaml struct of config
type YamlConfig struct {
Logger struct {
@@ -30,16 +20,18 @@ type YamlConfig struct {
Count int `yaml:"count"`
} `yaml:"logger"`
Rest []struct {
IPv4 string `yaml:"ipv4"`
IPv6 string `yaml:"ipv6"`
Port uint16 `yaml:"port"`
Scheme string `yaml:"scheme"`
ClientAuthType int `yaml:"clientAuthType"`
CaFile string `yaml:"caFile"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
} `yaml:"rest"`
// Rest []struct {
// IPv4 string `yaml:"ipv4"`
// IPv6 string `yaml:"ipv6"`
// Port uint16 `yaml:"port"`
// Scheme string `yaml:"scheme"`
// ClientAuthType int `yaml:"clientAuthType"`
// CaFile string `yaml:"caFile"`
// CertFile string `yaml:"certFile"`
// KeyFile string `yaml:"keyFile"`
// } `yaml:"rest"`
Rest []RestParam
WebServer struct {
Enabled bool `yaml:"enabled"`
@@ -85,7 +77,8 @@ type YamlConfig struct {
} `yaml:"omc"`
Alarm struct {
ForwardAlarm bool `yaml:"forwardAlarm"`
ForwardAlarm bool `yaml:"forwardAlarm"`
SMProxy string `yaml:"smProxy"`
Email struct {
Smtp string `yaml:"smtp"`
Port uint16 `yaml:"port"`
@@ -101,22 +94,14 @@ type YamlConfig struct {
TemplateCode string `yaml:"templateCode"`
} `yaml:"sms"`
SMSC struct {
Addr string `yaml:"addr"`
UserName string `yaml:"userName"`
Password string `yaml:"password"`
Addr string `yaml:"addr"`
SystemID string `yaml:"systemID"`
Password string `yaml:"password"`
SystemType string `yaml:"systemType"`
} `yaml:"smsc"`
} `yaml:"alarm"`
MML struct {
Port int `yaml:"port"`
Port2 int `yaml:"port2"`
Sleep int64 `yaml:"sleep"`
DeadLine int64 `yaml:"deadLine"`
User string `yaml:"user"`
Password string `ymal:"password"`
MmlHome string `yaml:"mmlHome"`
Upload string `yaml:"upload"`
} `yaml:"mml"`
MML MMLParam `yaml:"mml"`
NE struct {
Addr string `yaml:"addr"`
@@ -157,6 +142,42 @@ type YamlConfig struct {
} `yaml:"testConfig"`
}
type RestParam struct {
IPv4 string `yaml:"ipv4"`
IPv6 string `yaml:"ipv6"`
Port uint16 `yaml:"port"`
Scheme string `yaml:"scheme,omitempty" default:"http"`
ClientAuthType int `yaml:"clientAuthType"`
CaFile string `yaml:"caFile"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
}
type DbConfig struct {
Type string `yaml:"type"`
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Name string `yaml:"name"`
ConnParam string `yaml:"connParam,omitempty"`
Backup string `yaml:"backup"`
}
type MMLParam struct {
Port int `yaml:"port"`
Port2 int `yaml:"port2"`
Sleep int64 `yaml:"sleep"`
DeadLine int64 `yaml:"deadLine"`
SizeRow byte `yaml:"sizeRow"`
SizeCol byte `yaml:"sizeCol"`
BufferSize int `yaml:"bufferSize"`
User string `yaml:"user"`
Password string `ymal:"password"`
MmlHome string `yaml:"mmlHome"`
Upload string `yaml:"upload"`
}
type TestDatas struct {
UDM struct {
CapUsed uint32 `yaml:"capUsed"`
@@ -188,7 +209,22 @@ type TestDataMap struct {
NeTestDatas []map[string]NeTestData
}
var yamlConfig YamlConfig
var yamlConfig YamlConfig = NewYamlConfig()
// set default value for yaml config
func NewYamlConfig() YamlConfig {
return YamlConfig{
Database: DbConfig{
Type: "mysql",
ConnParam: "charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True",
},
MML: MMLParam{
SizeRow: 100,
SizeCol: 128,
BufferSize: 65535,
},
}
}
func ReadConfig(configFile string) {
yamlFile, err := os.ReadFile(configFile)
@@ -327,6 +363,23 @@ func GetDefaultUserAgent() string {
return "OMC-restagent/" + global.Version
}
func GetOMCHostUrl() string {
var omcip string = "127.0.0.1"
var rest RestParam = yamlConfig.Rest[0]
var port uint16 = rest.Port
if rest.IPv4 != "0.0.0.0" && rest.IPv4 != "" {
omcip = rest.IPv4
} else if rest.IPv6 != "::" && rest.IPv6 != "" {
omcip = "[" + rest.IPv6 + "]"
}
var scheme string = "http"
if rest.Scheme != "" {
scheme = rest.Scheme
}
return fmt.Sprintf("%s://%s:%d", scheme, omcip, port)
}
// const defaultConfigFile = "./etc/restconf.yaml"
// func init() {