修改:1、删除config.ini中非必要配置 2、将config中HttpPort设置给gin

This commit is contained in:
pengwang 2021-09-29 17:12:49 +08:00
parent 3e84eda51c
commit 5b77d49a5c
5 changed files with 12 additions and 63 deletions

View File

@ -2,16 +2,3 @@
AppMode = debug
HttpPort = :8080
[serial]
Name = /dev/tty.usbserial-1410,/dev/ttys1,/dev/tty.SLAB_USBtoUART
[network]
Name = eth0
[log]
#TraceLevel,DebugLevel,InfoLevel,WarnLevel,ErrorLevel
Level = DebugLevel
#true,false
SaveToFile = false
FileMaxCnt = 5

BIN
httpServer/.DS_Store vendored

Binary file not shown.

View File

@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)
func RouterWeb() {
func RouterWeb(port string) {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
@ -253,7 +253,7 @@ func RouterWeb() {
}
}
if err := router.Run(":8080"); err != nil {
if err := router.Run(port); err != nil {
setting.Logger.Errorf("gin run err,%v", err)
}
}

View File

@ -55,5 +55,5 @@ func main() {
report.ReportServiceInit()
httpServer.RouterWeb()
httpServer.RouterWeb(setting.HttpPort)
}

View File

@ -1,50 +1,21 @@
package setting
import (
"gopkg.in/ini.v1"
"log"
"os"
"path/filepath"
"gopkg.in/ini.v1"
)
var (
AppMode string
HttpPort string
LogLevel string //日志等级
LogSaveToFile bool //日志储存到文件中
LogFileMaxCnt uint //日志储存最多文件数量
AppMode string
HttpPort string
)
func LoadServer(file *ini.File){
AppMode = file.Section("server").Key("AppMode").MustString("debug")
HttpPort = file.Section("server").Key("HttpPort").MustString(":8080")
}
func LoadSerial(file *ini.File){
//type SerialPortTemplate struct{
// Name []string `json:"Name"`
//}
//
//SerialPortName := &SerialPortTemplate{}
err := file.Section("serial").MapTo(&SerialPortNameTemplateMap)
if err != nil{
log.Println(err)
}
}
func LoadLog(file *ini.File){
LogLevel = file.Section("log").Key("Level").MustString("DebugLevel")
LogSaveToFile = file.Section("log").Key("SaveToFile").MustBool(false)
LogFileMaxCnt = uint(file.Section("log").Key("FileMaxCnt").MustInt(10))
}
func LoadNetwork(file *ini.File) {
err := file.Section("network").MapTo(&NetworkNameList)
if err != nil {
log.Println(err)
}
func LoadServer(file *ini.File) {
AppMode = file.Section("server").Key("AppMode").MustString("debug")
HttpPort = file.Section("server").Key("HttpPort").MustString(":8080")
}
/**************获取配置信息************************/
@ -54,8 +25,8 @@ func GetConf() {
path := exeCurDir + "/config/config.ini"
iniFile, err := ini.Load(path)
if err != nil{
log.Println("Load config.ini err,",err)
if err != nil {
log.Println("Load config.ini err,", err)
cfg := ini.Empty()
@ -64,18 +35,9 @@ func GetConf() {
cfg.Section("server").Key("AppMode").SetValue("debug")
cfg.Section("server").Key("HttpPort").SetValue(":8080")
cfg.Section("serial").Key("serialPort").SetValue("/dev/ttyS0")
cfg.Section("network").Key("name").SetValue("eth0")
cfg.SaveTo(path)
return
}
LoadServer(iniFile)
LoadSerial(iniFile)
LoadNetwork(iniFile)
LoadLog(iniFile)
}