String增加获取Md5和Value方法
This commit is contained in:
parent
fc547a05b1
commit
d46ebe684c
31
string.go
31
string.go
@ -8,8 +8,10 @@
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -922,3 +924,32 @@ func (str String) ToAnySlice() AnySliceResult {
|
||||
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user