Commit 80a811ce by lichenggang

增加用户配置文件

parent 6c742843
Showing with 13 additions and 18 deletions
......@@ -11,11 +11,11 @@ import (
"log"
"regexp"
"sync"
. "web_log/config"
)
//var userMap = make(map[string]string)
var sessionIdMap = make(map[string]string)
var configPath string = "E:\\gotest\\test.json"
type Configs map[string]json.RawMessage
type MainConfig struct {
......@@ -27,18 +27,17 @@ var confs Configs
var instanceOnce sync.Once
func init() {
//userMap["weblog"] = "MTIzNDU2"
sessionIdMap["S1oI0nPch9PzJ0ClGEODdzbqcq85JK7YwnLesuTWayU="] = ""
}
//初始化读取配置文件
func Init(path string) *MainConfig {
if conf != nil && path != configPath {
log.Printf("the config is already initialized, oldPath=%s, path=%s", configPath, path)
func ReadUserConfig(path string) *MainConfig {
if conf != nil && path != UserConfigPath {
log.Printf("the config is already initialized, oldPath=%s, path=%s", UserConfigPath, path)
}
instanceOnce.Do(func() {
allConfigs, mainConfig := LoadConfig(path)
configPath = path
UserConfigPath = path
conf = mainConfig
confs = allConfigs
})
......@@ -48,7 +47,7 @@ func Init(path string) *MainConfig {
//获取配置文件路径
func ConfigPath() string {
return configPath
return UserConfigPath
}
/**
......@@ -64,7 +63,7 @@ func VerifyUser(name string, pwd string) (result bool, msg string) {
}
path := ConfigPath()
//初始化配置文件
Init(path)
ReadUserConfig(path)
// 密码md5加密
pwd = EnMD5PwdCode(pwd)
if mapPwd, ok := confs[name]; ok {
......
package main
import (
"fmt"
"github.com/kataras/iris/v12"
"os"
"web_log/code"
"web_log/config"
)
// example
func main() {
Directory := "E:\\test_logs" // directory of the log
addrs := "0.0.0.0:9997"
logenv := os.Getenv("GOLOGENV")
if logenv == "TEST" {
Directory = "/data/soft/bigdatav3.0/test_rsync_log"
}
if logenv == "PRODUCT" {
Directory = "/data/soft/rsync_log"
}
app := code.GetApp(Directory)
config.InitConfig()
fmt.Printf("查看日志目录: %s \n用户配置文件: %s", config.Directory, config.UserConfigPath)
app := code.GetApp(config.Directory)
app.Run(iris.Addr(addrs), iris.WithCharset("UTF-8"))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment