fix: timzone issue

This commit is contained in:
2024-03-29 09:38:25 +08:00
parent 0ff07a7ccd
commit e22abdc890
7 changed files with 89 additions and 49 deletions

View File

@@ -12,13 +12,14 @@ import (
)
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"`
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"`
}
// Yaml struct of config
@@ -30,16 +31,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"`
@@ -157,6 +160,17 @@ 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 TestDatas struct {
UDM struct {
CapUsed uint32 `yaml:"capUsed"`
@@ -188,7 +202,17 @@ 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&loc=Local",
},
}
}
func ReadConfig(configFile string) {
yamlFile, err := os.ReadFile(configFile)
@@ -327,6 +351,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() {