From e5dfbb23ac6fd3fc857fa93c5f6c4cb934db1458 Mon Sep 17 00:00:00 2001 From: gigibox <gigibox@163.com> Date: 星期二, 20 六月 2023 16:18:48 +0800 Subject: [PATCH] 添加sql语句校验, 查询接口只允许查询操作 --- config/config.go | 43 ++++++++++++++++++++++++++++++++----------- 1 files changed, 32 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 80b5711..1627c5b 100644 --- a/config/config.go +++ b/config/config.go @@ -9,24 +9,44 @@ ) 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_webapi"` // nsq HTTP鎺ュ彛鍦板潃 + OrderTopic string `json:"order_topic"` // 璁㈠崟涓婃姤鐨則opic + InventoryTopic string `json:"inventory_topic"` // 搴撳瓨涓婃姤鐨則opic + QueryTopic string `json:"query_topic"` // 閲戣澏鏌ヨ鎺ュ彛鐨則opic + ReplyTopic string `json:"reply_topic"` // 閲戣澏鍝嶅簲鏌ヨ鎺ュ彛鐨則opic + SyncInterval int `json:"interval"` // 鍚屾鐨勬椂闂撮棿闅�, 鍗曚綅/绉� + Debug bool `json:"debug"` // 鏈湴璋冭瘯, 鍙栨湰鍦版暟鎹� } 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 = "aps.factory.erp.seorder" + Options.InventoryTopic = "aps.factory.erp.inventory" + Options.QueryTopic = "aps.factory.erp.k3resource" + Options.ReplyTopic = "aps.factory.erp.k3reply" + Options.SyncInterval = 60 + Options.Debug = false } func Load() { if !pathExists(configPath) { + DefaultConfig() SaveConfig() } else { file, _ := os.Open(configPath) @@ -35,8 +55,6 @@ fd := json.NewDecoder(file) fd.Decode(&Options) - - fmt.Printf("%v\n", Options) } } @@ -44,8 +62,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