Prechádzať zdrojové kódy

删除配置文件读取方式

zhangjq 6 rokov pred
rodič
commit
a58bea3358
2 zmenil súbory, kde vykonal 17 pridanie a 9 odobranie
  1. 8 0
      config/config.go
  2. 9 9
      utils/pwd.go

+ 8 - 0
config/config.go

@@ -49,4 +49,12 @@ func (c *ApiConfig)GetInt(key string) int64 {
 		ParseConfig()
 	}
 	return  _config.Integer(key, 0)
+}
+
+
+func (c *ApiConfig)GetBool(key string, def bool) bool {
+	if _config == nil{
+		ParseConfig()
+	}
+	return  _config.Boolean(key, def)
 }

+ 9 - 9
utils/pwd.go

@@ -10,14 +10,15 @@ import (
 	"encoding/base64"
 	"encoding/hex"
 
-	"github.com/astaxie/beego"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/logs"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
 )
 
 func HashPassword(password, salt string) string {
 	h := md5.New()
-	enableDbSalt, _ := NewConfig().Bool("System::EnableDBSalt", true) //beego.AppConfig.Bool("System::EnableDBSalt")
-	customSalt := NewConfig().String("System::PasswordSalt")          //beego.AppConfig.String("System::PasswordSalt")
-	enableBase64, _ := NewConfig().Bool("System::PasswordEnableBase64", true)
+	enableDbSalt, _ := config.AppConfig.GetBool("System::EnableDBSalt", true)
+	customSalt := config.AppConfig.GetKey("System::PasswordSalt")
+	enableBase64, _ := config.AppConfig.GetBool("System::PasswordEnableBase64", true)
 	if !enableDbSalt {
 		h.Write([]byte(password))
 		if len(customSalt) > 0 {
@@ -26,26 +27,25 @@ func HashPassword(password, salt string) string {
 			h.Reset()
 			h.Write([]byte(md5Str + customSalt))
 		}
-		//if beego.AppConfig.String("System::PasswordEnableBase64") == "true" {
 		if enableBase64 {
 			base64_str := base64.StdEncoding.EncodeToString(h.Sum(nil))
-			beego.Debug("启用编码:", base64_str)
+			logs.Debug("启用编码:", base64_str)
 			return base64_str
 		} else {
 			str := hex.EncodeToString(h.Sum(nil))
-			beego.Debug("未启用编码:", str)
+			logs.Debug("未启用编码:", str)
 			return str
 		}
 	} else {
 		h.Write([]byte(password))
 		md5Str := hex.EncodeToString(h.Sum(nil))
-		beego.Debug("第一次加密:", md5Str)
+		logs.Debug("第一次加密:", md5Str)
 		if len(salt) > 0 {
 			h.Reset()
 			h.Write([]byte(md5Str + salt))
 			md5Str = hex.EncodeToString(h.Sum(nil))
 		}
-		beego.Debug("第二次加密:", md5Str)
+		logs.Debug("第二次加密:", md5Str)
 		return md5Str
 	}
 }