From 9dc83b2157b8b43c9c9411b86abb3e9a8767320d Mon Sep 17 00:00:00 2001 From: sre Date: Fri, 17 Jun 2022 11:34:15 +0800 Subject: [PATCH] StrTool --- str/str.go | 4 ++-- str/str_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/str/str.go b/str/str.go index bfcab1f..95b1ec3 100644 --- a/str/str.go +++ b/str/str.go @@ -6,13 +6,13 @@ type Str struct { } // struing to hex -func HexEncode(str string) string { +func (s *Str) HexEncode(str string) string { byteStr := []byte(str) return hex.EncodeToString(byteStr) } // hex to string -func HexDecode(str string) (string, error) { +func (s *Str) HexDecode(str string) (string, error) { hexStr, err := hex.DecodeString(str) if err != nil { panic(err) diff --git a/str/str_test.go b/str/str_test.go index fa1355b..7959170 100644 --- a/str/str_test.go +++ b/str/str_test.go @@ -5,11 +5,13 @@ import ( "testing" ) +var StrTool Str + func TestHexEncode(t *testing.T) { - fmt.Println(HexEncode("hello world!")) + fmt.Println(StrTool.HexEncode("hello world!")) //68656c6c6f20776f726c6421 } func TestHexDecode(t *testing.T) { - fmt.Println(HexDecode("68656c6c6f20776f726c6421")) + fmt.Println(StrTool.HexDecode("68656c6c6f20776f726c6421")) //hello world! }