Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package securityUtil
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 对字符串进行SHA1加密,并且可以选择返回大、小写
|
||||
// s:输入字符串
|
||||
// ifUpper:输出是否大写
|
||||
// 返回值:md5加密后的字符串
|
||||
func Sha1String(s string, ifUpper bool) string {
|
||||
if len(s) == 0 {
|
||||
panic(errors.New("input string can't be empty"))
|
||||
}
|
||||
|
||||
return Sha1Bytes([]byte(s), ifUpper)
|
||||
}
|
||||
|
||||
// 对字符数组进行SHA1加密,并且可以选择返回大、小写
|
||||
// b:输入字符数组
|
||||
// ifUpper:输出是否大写
|
||||
// 返回值:md5加密后的字符串
|
||||
func Sha1Bytes(b []byte, ifUpper bool) string {
|
||||
if len(b) == 0 {
|
||||
panic(errors.New("input []byte can't be empty"))
|
||||
}
|
||||
|
||||
sha1Instance := sha1.New()
|
||||
sha1Instance.Write(b)
|
||||
result := sha1Instance.Sum([]byte(""))
|
||||
if ifUpper {
|
||||
return fmt.Sprintf("%X", result)
|
||||
} else {
|
||||
return fmt.Sprintf("%x", result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package mysqlUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewDBConfig(t *testing.T) {
|
||||
connectionString := "root:moqikaka3306@tcp(10.1.0.10:3306)/gameserver_data?charset=utf8&parseTime=true&loc=Local&timeout=60s"
|
||||
maxOpenConns := 10
|
||||
maxIdleConns := 5
|
||||
|
||||
dbConfigObj := NewDBConfig(connectionString, maxOpenConns, maxIdleConns)
|
||||
if connectionString != dbConfigObj.ConnectionString {
|
||||
t.Errorf("Expected %s, but now %s", connectionString, dbConfigObj.ConnectionString)
|
||||
}
|
||||
|
||||
if maxOpenConns != dbConfigObj.MaxOpenConns {
|
||||
t.Errorf("Expected %d, but now %d", maxOpenConns, dbConfigObj.MaxOpenConns)
|
||||
}
|
||||
|
||||
if maxIdleConns != dbConfigObj.MaxIdleConns {
|
||||
t.Errorf("Expected %d, but now %d", maxIdleConns, dbConfigObj.MaxIdleConns)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDBConfig2(t *testing.T) {
|
||||
dbConfigStr := "root:moqikaka3306@tcp(10.1.0.10:3306)/gameserver_data?charset=utf8&parseTime=true&loc=Local&timeout=60s||MaxOpenConns=10||MaxIdleConns2=5"
|
||||
|
||||
if _, err := NewDBConfig2(dbConfigStr); err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
dbConfigStr = "root:moqikaka3306@tcp(10.1.0.10:3306)/gameserver_data?charset=utf8&parseTime=true&loc=Local&timeout=60s||MaxOpenConns=10||MaxIdleConns=5"
|
||||
dbConfigObj, err := NewDBConfig2(dbConfigStr)
|
||||
if err != nil {
|
||||
t.Errorf("there should be no err, but now has.")
|
||||
}
|
||||
|
||||
connectionString := "root:moqikaka3306@tcp(10.1.0.10:3306)/gameserver_data?charset=utf8&parseTime=true&loc=Local&timeout=60s"
|
||||
maxOpenConns := 10
|
||||
maxIdleConns := 5
|
||||
|
||||
if connectionString != dbConfigObj.ConnectionString {
|
||||
t.Errorf("Expected %s, but now %s", connectionString, dbConfigObj.ConnectionString)
|
||||
}
|
||||
|
||||
if maxOpenConns != dbConfigObj.MaxOpenConns {
|
||||
t.Errorf("Expected %d, but now %d", maxOpenConns, dbConfigObj.MaxOpenConns)
|
||||
}
|
||||
|
||||
if maxIdleConns != dbConfigObj.MaxIdleConns {
|
||||
t.Errorf("Expected %d, but now %d", maxIdleConns, dbConfigObj.MaxIdleConns)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user