diff --git a/string.go b/string.go index b3cb3dc..aa244df 100644 --- a/string.go +++ b/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) +}