String增加获取Md5和Value方法

This commit is contained in:
白茶清欢 2023-05-16 12:12:18 +08:00
parent fc547a05b1
commit d46ebe684c

View File

@ -8,8 +8,10 @@
package wrapper package wrapper
import ( import (
"crypto/md5"
"errors" "errors"
"git.zhangdeman.cn/zhangdeman/util" "git.zhangdeman.cn/zhangdeman/util"
"io"
"strings" "strings"
) )
@ -922,3 +924,32 @@ func (str String) ToAnySlice() AnySliceResult {
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value) result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
return result return result
} }
// Md5 计算Md5值
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:08 2023/5/16
func (str String) Md5() StringResult {
h := md5.New()
_, err := io.WriteString(h, str.Value())
if nil != err {
return StringResult{
Value: "",
Err: err,
}
}
return StringResult{
Value: string(h.Sum(nil)),
Err: nil,
}
}
// Value ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:11 2023/5/16
func (str String) Value() string {
return string(str)
}