Bump github.com/gookit/config/v2 from 2.2.3 to 2.2.4
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
Ralf Haferkamp
parent
30784affc4
commit
0df009eae0
+18
-55
@@ -94,84 +94,47 @@ func URLDecode(s string) string {
|
||||
// -------------------- base encode --------------------
|
||||
//
|
||||
|
||||
// base32 encoding with no padding
|
||||
var (
|
||||
B32Std = base32.StdEncoding.WithPadding(base32.NoPadding)
|
||||
B32Hex = base32.HexEncoding.WithPadding(base32.NoPadding)
|
||||
)
|
||||
|
||||
// B32Encode base32 encode
|
||||
func B32Encode(str string) string {
|
||||
return base32.StdEncoding.EncodeToString([]byte(str))
|
||||
return B32Std.EncodeToString([]byte(str))
|
||||
}
|
||||
|
||||
// B32Decode base32 decode
|
||||
func B32Decode(str string) string {
|
||||
dec, _ := base32.StdEncoding.DecodeString(str)
|
||||
dec, _ := B32Std.DecodeString(str)
|
||||
return string(dec)
|
||||
}
|
||||
|
||||
// B64Std base64 encoding with no padding
|
||||
var B64Std = base64.StdEncoding.WithPadding(base64.NoPadding)
|
||||
|
||||
// B64Encode base64 encode
|
||||
func B64Encode(str string) string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(str))
|
||||
return B64Std.EncodeToString([]byte(str))
|
||||
}
|
||||
|
||||
// B64EncodeBytes base64 encode
|
||||
func B64EncodeBytes(src []byte) []byte {
|
||||
buf := make([]byte, base64.StdEncoding.EncodedLen(len(src)))
|
||||
base64.StdEncoding.Encode(buf, src)
|
||||
|
||||
buf := make([]byte, B64Std.EncodedLen(len(src)))
|
||||
B64Std.Encode(buf, src)
|
||||
return buf
|
||||
}
|
||||
|
||||
// B64Decode base64 decode
|
||||
func B64Decode(str string) string {
|
||||
dec, _ := base64.StdEncoding.DecodeString(str)
|
||||
dec, _ := B64Std.DecodeString(str)
|
||||
return string(dec)
|
||||
}
|
||||
|
||||
// B64DecodeBytes base64 decode
|
||||
func B64DecodeBytes(str string) []byte {
|
||||
dbuf := make([]byte, base64.StdEncoding.DecodedLen(len(str)))
|
||||
n, _ := base64.StdEncoding.Decode(dbuf, []byte(str))
|
||||
|
||||
func B64DecodeBytes(str []byte) []byte {
|
||||
dbuf := make([]byte, B64Std.DecodedLen(len(str)))
|
||||
n, _ := B64Std.Decode(dbuf, str)
|
||||
return dbuf[:n]
|
||||
}
|
||||
|
||||
// BaseEncoder interface
|
||||
type BaseEncoder interface {
|
||||
Encode(dst []byte, src []byte)
|
||||
EncodeToString(src []byte) string
|
||||
Decode(dst []byte, src []byte) (n int, err error)
|
||||
DecodeString(s string) ([]byte, error)
|
||||
}
|
||||
|
||||
// BaseType for base encoding
|
||||
type BaseType uint8
|
||||
|
||||
// types for base encoding
|
||||
const (
|
||||
BaseTypeStd BaseType = iota
|
||||
BaseTypeHex
|
||||
BaseTypeURL
|
||||
BaseTypeRawStd
|
||||
BaseTypeRawURL
|
||||
)
|
||||
|
||||
// Encoding instance
|
||||
func Encoding(base int, typ BaseType) BaseEncoder {
|
||||
if base == 32 {
|
||||
switch typ {
|
||||
case BaseTypeHex:
|
||||
return base32.HexEncoding
|
||||
default:
|
||||
return base32.StdEncoding
|
||||
}
|
||||
}
|
||||
|
||||
// base 64
|
||||
switch typ {
|
||||
case BaseTypeURL:
|
||||
return base64.URLEncoding
|
||||
case BaseTypeRawURL:
|
||||
return base64.RawURLEncoding
|
||||
case BaseTypeRawStd:
|
||||
return base64.RawStdEncoding
|
||||
default:
|
||||
return base64.StdEncoding
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user