Skip to content

Commit

Permalink
👔 up: rename the new sub package encodx to encodes
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 16, 2023
1 parent ff8619f commit 5968127
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 43 deletions.
2 changes: 1 addition & 1 deletion encodx/encodx.go → encodes/encodes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package encodx
package encodes

Check warning on line 1 in encodes/encodes.go

View workflow job for this annotation

GitHub Actions / Test on go 1.20 and ubuntu-latest

should have a package comment

import (
"encoding/base32"
Expand Down
29 changes: 29 additions & 0 deletions encodes/encodes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package encodes_test

import (
"testing"

"github.com/gookit/goutil/encodes"
"github.com/gookit/goutil/testutil/assert"
)

func TestBaseDecode(t *testing.T) {
is := assert.New(t)

is.Eq("GEZGCYTD", encodes.B32Encode("12abc"))
is.Eq("12abc", encodes.B32Decode("GEZGCYTD"))

// b23 hex
is.Eq("64P62OJ3", encodes.B32Hex.EncodeToString([]byte("12abc")))
// fmt.Println(time.Now().Format("20060102150405"))
dateStr := "20230908101122"
is.Eq("68O34CPG74O3GC9G64OJ4CG", encodes.B32Hex.EncodeToString([]byte(dateStr)))

is.Eq("YWJj", encodes.B64Encode("abc"))
is.Eq("abc", encodes.B64Decode("YWJj"))

is.Eq([]byte("YWJj"), encodes.B64EncodeBytes([]byte("abc")))
is.Eq([]byte("abc"), encodes.B64DecodeBytes([]byte("YWJj")))

is.Eq("MTJhYmM", encodes.B64URL.EncodeToString([]byte("12abc")))
}
10 changes: 5 additions & 5 deletions encodx/hashutil/hashutil.go → encodes/hashutil/hashutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"hash/crc64"
"strings"

"github.com/gookit/goutil/encodx"
"github.com/gookit/goutil/encodes"
)

// hash algorithm names
Expand Down Expand Up @@ -59,8 +59,8 @@ func Hash32(algo string, src any) string {
// Base32Bytes generate base32 hash bytes by given algorithm
func Base32Bytes(algo string, src any) []byte {
bs := HashSum(algo, src)
dst := make([]byte, encodx.B32Hex.EncodedLen(len(bs)))
encodx.B32Hex.Encode(dst, bs)
dst := make([]byte, encodes.B32Hex.EncodedLen(len(bs)))
encodes.B32Hex.Encode(dst, bs)
return dst
}

Expand All @@ -72,8 +72,8 @@ func Hash64(algo string, src any) string {
// Base64Bytes generate base64 hash bytes by given algorithm
func Base64Bytes(algo string, src any) []byte {
bs := HashSum(algo, src)
dst := make([]byte, encodx.B64Std.EncodedLen(len(bs)))
encodx.B64Std.Encode(dst, bs)
dst := make([]byte, encodes.B64Std.EncodedLen(len(bs)))
encodes.B64Std.Encode(dst, bs)
return dst
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gookit/goutil/byteutil"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/strutil/secutil"
"github.com/gookit/goutil/encodes/secutil"
"github.com/gookit/goutil/testutil/assert"
)

Expand Down
File renamed without changes.
29 changes: 0 additions & 29 deletions encodx/encodx_test.go

This file was deleted.

7 changes: 2 additions & 5 deletions strutil/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ func B32Decode(str string) string {
return string(dec)
}

// base64 encoding with no padding
var (
B64Std = base64.StdEncoding.WithPadding(base64.NoPadding)
B64URL = base64.URLEncoding.WithPadding(base64.NoPadding)
)
// B64Std base64 encoding with no padding
var B64Std = base64.StdEncoding.WithPadding(base64.NoPadding)

// B64Encode base64 encode
func B64Encode(str string) string {
Expand Down
3 changes: 1 addition & 2 deletions strutil/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/gookit/goutil/byteutil"
"github.com/gookit/goutil/encodx"
)

// some consts string chars
Expand Down Expand Up @@ -89,7 +88,7 @@ func RandWithTpl(n int, letters string) string {
// token, err := RandomString(16) // eg: "I7S4yFZddRMxQoudLZZ-eg"
func RandomString(length int) (string, error) {
b, err := RandomBytes(length)
return encodx.B64URL.EncodeToString(b), err
return encodes.B64URL.EncodeToString(b), err

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and ubuntu-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.18 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and windows-latest

undefined: encodes

Check failure on line 91 in strutil/random.go

View workflow job for this annotation

GitHub Actions / Test on go 1.19 and windows-latest

undefined: encodes
}

// RandomBytes generate
Expand Down

0 comments on commit 5968127

Please sign in to comment.