-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat - add array and crypt, and complete other modules.
- Loading branch information
Nicola Strappazzon C
committed
Oct 8, 2023
1 parent
56545a1
commit 59037f4
Showing
10 changed files
with
292 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package array | ||
|
||
func StringIn(key string, list []string) bool { | ||
for _, l := range list { | ||
if l == key { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package array_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/debeando/go-common/array" | ||
) | ||
|
||
func TestStringIn(t *testing.T) { | ||
list := []string{"foo", "bar"} | ||
result := array.StringIn("bar", list) | ||
|
||
if !result { | ||
t.Error("Expected: false") | ||
} | ||
|
||
result = array.StringIn("test", list) | ||
|
||
if result { | ||
t.Error("Expected: true") | ||
} | ||
|
||
result = array.StringIn("", list) | ||
|
||
if result { | ||
t.Error("Expected: false") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package crypt | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
) | ||
|
||
func MD5(s string) string { | ||
hash := md5.Sum([]byte(s)) | ||
return hex.EncodeToString(hash[:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package crypt_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/debeando/go-common/crypt" | ||
) | ||
|
||
func TestMD5(t *testing.T) { | ||
expected := "098f6bcd4621d373cade4e832627b4f6" | ||
result := crypt.MD5("test") | ||
|
||
if result != expected { | ||
t.Error("Expected: 098f6bcd4621d373cade4e832627b4f6") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.