From ff3cadba4a63cd1b63cd0e36358f49ccedb88bef Mon Sep 17 00:00:00 2001 From: gigibox <gigibox@163.com> Date: 星期四, 15 六月 2023 10:02:20 +0800 Subject: [PATCH] 完成基本功能 --- config/config.go | 35 ++++++++++++++++++++++++++--------- 1 files changed, 26 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index 80b5711..b50fcf5 100644 --- a/config/config.go +++ b/config/config.go @@ -9,24 +9,38 @@ ) type Config struct { - WebPort string `json:"web_port"` - SqlAddr string `json:"sql_addr"` - SqlDBName string `json:"sql_db_name"` - SqlUsername string `json:"sql_username"` - SqlPassword string `json:"sql_password"` + WebPort string `json:"web_port"` // 鏈湴web鏈嶅姟缁戝畾鎺ュ彛 + SqlAddr string `json:"sql_addr"` // 鏁版嵁搴搃p鍦板潃, 涓嶅姞绔彛鍙�, 榛樿浣跨敤1433绔彛 + SqlDBName string `json:"sql_db_name"` // 鏁版嵁搴撳悕绉� + SqlUsername string `json:"sql_username"` // 鏁版嵁搴撶敤鎴� + SqlPassword string `json:"sql_password"` // 鏁版嵁搴撳瘑鐮� + NsqServer string `json:"nsq_server"` // nsq TCP鏈嶅姟绔湴鍧� + NsqWebApi string `json:"nsq_server"` // nsq HTTP鎺ュ彛鍦板潃 + OrderTopic string `json:"order_topic"` // 璁㈠崟涓婃姤鐨則opic + InventoryTopic string `json:"inventory_topic"` // 搴撳瓨涓婃姤鐨則opic + SyncInterval int `json:"interval"` // 鍚屾鐨勬椂闂撮棿闅�, 鍗曚綅/绉� } const configPath = "config.json" var Options Config -// Init is an exported method that takes the environment starts the viper -// (external lib) and returns the configuration struct. -func init() { +func DefaultConfig() { + Options.WebPort = "10210" + Options.SqlAddr = "127.0.0.1" + Options.SqlDBName = "dbname" + Options.SqlUsername = "sa" + Options.SqlPassword = "123456" + Options.NsqServer = "fai365.com:4150" + Options.NsqWebApi = "http://121.31.232.83:9080/api/nsq/pub?topic=your_topic" + Options.OrderTopic = "/province/city/factoryNo/kingdee_seOrder" + Options.InventoryTopic = "/province/city/factoryNo/kingdee_inventory" + Options.SyncInterval = 60 } func Load() { if !pathExists(configPath) { + DefaultConfig() SaveConfig() } else { file, _ := os.Open(configPath) @@ -44,8 +58,11 @@ b, err := json.Marshal(Options) if err == nil { var out bytes.Buffer + err = json.Indent(&out, b, "", " ") - ioutil.WriteFile(configPath, out.Bytes(), 0644) + if err == nil { + err = ioutil.WriteFile(configPath, out.Bytes(), 0644) + } } return err -- Gitblit v1.8.0