Commit 80a811ce by lichenggang

增加用户配置文件

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