Skip to content

Commit

Permalink
Merge pull request #15 from zouchangfu/main
Browse files Browse the repository at this point in the history
feat: add md5x
  • Loading branch information
qicz authored May 15, 2022
2 parents b0f3234 + 4583709 commit 08e00b6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gox/md5x/md5x.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2022, OpeningO
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package md5x

import (
"crypto/md5"
"encoding/hex"
)

// Md5x Generate md5
func Md5x(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
26 changes: 26 additions & 0 deletions gox/md5x/md5x_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package md5x

import "testing"

func TestMd5x(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want string
}{
{
args: args{"hello"},
want: "5d41402abc4b2a76b9719d911017c592",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Md5x(tt.args.str); got != tt.want {
t.Errorf("Md5x() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 08e00b6

Please sign in to comment.