update
This commit is contained in:
1 parent
f25da5f1ee
commit
1df55e75e5
72 files changed
+1401
-1559
No files matched your search
+3
-12
@@ -9,20 +9,11 @@ import (
|
||||
func StrToInt(err error, index string) int {
|
||||
result, err := strconv.Atoi(index)
|
||||
if err != nil {
|
||||
AssertErr(err, "string to int error"+err.Error(), -1)
|
||||
HasError(err, "string to int error"+err.Error(), -1)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
//加密
|
||||
func Encrypt(e string) ([]byte, error) {
|
||||
//var s []byte
|
||||
s, err := bcrypt.GenerateFromPassword([]byte(e), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s, err
|
||||
}
|
||||
|
||||
func CompareHashAndPassword(e string, p string) (bool, error) {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(e), []byte(p))
|
||||
@@ -46,11 +37,11 @@ func Assert(condition bool, msg string, code ...int) {
|
||||
}
|
||||
}
|
||||
|
||||
// AssertErr 错误断言
|
||||
// HasError 错误断言
|
||||
// 当 error 不为 nil 时触发 panic
|
||||
// 对于当前请求不会再执行接下来的代码,并且返回指定格式的错误信息和错误码
|
||||
// 若 msg 为空,则默认为 error 中的内容
|
||||
func AssertErr(err error, msg string, code ...int) {
|
||||
func HasError(err error, msg string, code ...int) {
|
||||
if err != nil {
|
||||
statusCode := 200
|
||||
if len(code) > 0 {
|
||||
|
||||
Reference in new issue
Block a user