From c6fbee9a76f75ecae112cf2e0b00b2eace4c580c Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Fri, 29 Mar 2024 10:09:43 +0800 Subject: [PATCH] fix: timezone parse time issue --- captrace/captrace.go | 2 +- captrace/config/config.go | 32 +++++++++++++++++++++++--------- crontask/config.go | 33 +++++++++++++++++++++++---------- crontask/crontask.go | 2 +- sshsvc/config/config.go | 33 +++++++++++++++++++++++---------- sshsvc/sshsvc.go | 2 +- 6 files changed, 72 insertions(+), 32 deletions(-) diff --git a/captrace/captrace.go b/captrace/captrace.go index 09133f74..5434a9a3 100644 --- a/captrace/captrace.go +++ b/captrace/captrace.go @@ -621,7 +621,7 @@ func main() { log.Infof("========================= OMC captrace startup =========================") log.Infof("OMC captrace version: %s %s %s", global.Version, global.BuildTime, global.GoVer) err := dborm.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password, - conf.Database.Host, conf.Database.Port, conf.Database.Name) + conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam) if err != nil { fmt.Println("dborm.initDbClient err:", err) os.Exit(2) diff --git a/captrace/config/config.go b/captrace/config/config.go index f1b2f9af..378c2256 100644 --- a/captrace/config/config.go +++ b/captrace/config/config.go @@ -11,6 +11,17 @@ 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"` + ConnParam string `yaml:"connParam,omitempty"` + Backup string `yaml:"backup"` +} + // Yaml struct of config type YamlConfig struct { Logger struct { @@ -24,17 +35,20 @@ type YamlConfig struct { Addr string `yaml:"addr"` } `yaml:"gtp"` - Database 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"` - } `yaml:"database"` + Database DbConfig `yaml:"database"` } -var YamlConf YamlConfig +var YamlConf 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) diff --git a/crontask/config.go b/crontask/config.go index 869d3600..5a4b441a 100644 --- a/crontask/config.go +++ b/crontask/config.go @@ -12,6 +12,17 @@ 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"` + ConnParam string `yaml:"connParam,omitempty"` + Backup string `yaml:"backup"` +} + // Yaml struct of config type YamlConfig struct { Logger struct { @@ -30,15 +41,7 @@ type YamlConfig struct { Vendor string `yaml:"vendor"` } `yaml:"omc"` - Database 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:"database"` + Database DbConfig `yaml:"database"` Tasks struct { File string `yaml:"file"` @@ -58,7 +61,17 @@ type YamlConfig struct { } `yaml:"nbi"` } -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) error { yamlFile, err := os.ReadFile(configFile) diff --git a/crontask/crontask.go b/crontask/crontask.go index fabd6b63..ecea0b46 100644 --- a/crontask/crontask.go +++ b/crontask/crontask.go @@ -17,7 +17,7 @@ func main() { log.Infof("OMC crontask version: %s %s %s", global.Version, global.BuildTime, global.GoVer) err := dborm.InitDbClient(yamlConfig.Database.Type, yamlConfig.Database.User, yamlConfig.Database.Password, - yamlConfig.Database.Host, yamlConfig.Database.Port, yamlConfig.Database.Name) + yamlConfig.Database.Host, yamlConfig.Database.Port, yamlConfig.Database.Name, yamlConfig.Database.ConnParam) if err != nil { fmt.Println("dborm.initDbClient err:", err) os.Exit(1) diff --git a/sshsvc/config/config.go b/sshsvc/config/config.go index f99d0978..f4d7a589 100644 --- a/sshsvc/config/config.go +++ b/sshsvc/config/config.go @@ -13,6 +13,17 @@ 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"` + ConnParam string `yaml:"connParam,omitempty"` + Backup string `yaml:"backup"` +} + // Yaml struct of config type YamlConfig struct { Logger struct { @@ -39,15 +50,7 @@ type YamlConfig struct { MmlHome string `yaml:"mmlHome"` } `yaml:"sshd"` - Database 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:"database"` + Database DbConfig `yaml:"database"` OMC struct { HttpUri string `yaml:"httpUri"` @@ -55,7 +58,17 @@ type YamlConfig struct { } `yaml:"omc"` } -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) diff --git a/sshsvc/sshsvc.go b/sshsvc/sshsvc.go index a7671e2a..9dab6ca2 100644 --- a/sshsvc/sshsvc.go +++ b/sshsvc/sshsvc.go @@ -31,7 +31,7 @@ func init() { log.Infof("========================= OMC sshsvc startup =========================") log.Infof("OMC sshsvc version: %s %s %s", global.Version, global.BuildTime, global.GoVer) db := conf.Database - err := dborm.InitDbClient(db.Type, db.User, db.Password, db.Host, db.Port, db.Name) + err := dborm.InitDbClient(db.Type, db.User, db.Password, db.Host, db.Port, db.Name, db.ConnParam) if err != nil { fmt.Println("dborm.initDbClient err:", err) os.Exit(1)