File tree 2 files changed +56
-0
lines changed
2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, OpeningO
3
+ * All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ package md5x
19
+
20
+ import (
21
+ "crypto/md5"
22
+ "encoding/hex"
23
+ )
24
+
25
+ // Md5x Generate md5
26
+ func Md5x (str string ) string {
27
+ h := md5 .New ()
28
+ h .Write ([]byte (str ))
29
+ return hex .EncodeToString (h .Sum (nil ))
30
+ }
Original file line number Diff line number Diff line change
1
+ package md5x
2
+
3
+ import "testing"
4
+
5
+ func TestMd5x (t * testing.T ) {
6
+ type args struct {
7
+ str string
8
+ }
9
+ tests := []struct {
10
+ name string
11
+ args args
12
+ want string
13
+ }{
14
+ {
15
+ args : args {"hello" },
16
+ want : "5d41402abc4b2a76b9719d911017c592" ,
17
+ },
18
+ }
19
+ for _ , tt := range tests {
20
+ t .Run (tt .name , func (t * testing.T ) {
21
+ if got := Md5x (tt .args .str ); got != tt .want {
22
+ t .Errorf ("Md5x() = %v, want %v" , got , tt .want )
23
+ }
24
+ })
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments