From d46ebe684c29f8f0f1c3365fb63894841c7875b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 16 May 2023 12:12:18 +0800 Subject: [PATCH] =?UTF-8?q?String=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96Md5?= =?UTF-8?q?=E5=92=8CValue=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- string.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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) +}