### 项目介绍
* go-encoding 是 go常用编码解码库
* 算法包括: (Hex/Base32/Base45/Base58/Base62/Base64/Base85/Base91/Base100/MorseITU/JSON)
* 项目地址: https://github.com/deatil/go-encoding
### 下载安装
~~~
go get -u github.com/deatil/go-encoding
~~~
### 开始使用
~~~go
package main
import (
"fmt"
"github.com/deatil/go-encoding/encoding"
)
func main() {
oldData := "useData"
// Base64 编码
base64Data := encoding.FromString(oldData).Base64Encode().ToString()
fmt.Println("Base64 编码为:", base64Data)
// Base64 解码
base64DecodeData := encoding.FromString(base64Data).Base64Decode().ToString()
fmt.Println("Base64 解码为:", base64DecodeData)
}
~~~
### 格式说明
~~~go
base64Data := encoding.
FromString(oldData). // 输入数据
Base64Encode(). // 编码方式/解码方式
ToString() // 输出数据
~~~
### 输入输出数据
* 输入数据:
`FromBytes(data []byte)`, `FromString(data string)`, `FromReader(reader io.Reader)`
* 输出数据:
`String() string`, `ToBytes() []byte`, `ToString() string`, `ToReader() io.Reader`
### 常用解码编码
* 编码方式:
`Base32Encode()`, `Base32HexEncode()`, `Base32EncodeWithEncoder(encoder string)`,
`Base45Encode()`,
`Base58Encode()`,
`Base62Encode()`,
`Base64Encode()`, `Base64URLEncode()`, `Base64RawEncode()`, `Base64RawURLEncode()`, `Base64SegmentEncode()`, `Base64EncodeWithEncoder(encoder string)`,
`Base85Encode()`,
`Base91Encode()`,
`Base100Encode()`,
`Basex2Encode()`, `Basex16Encode()`, `Basex62Encode()`, `BasexEncodeWithEncoder(encoder string)`,
`HexEncode()`,
`MorseITUEncode()`,
`SafeURLEncode()`,
`SerializeEncode()`,
`JSONEncode(data any)`, `JSONIteratorEncode(data any)`, `JSONIteratorIndentEncode(v any, prefix, indent string)`,
`GobEncode(data any)`
* 解码方式:
`Base32Decode()`, `Base32HexDecode()`, `Base32DecodeWithEncoder(encoder string)`,
`Base45Decode()`,
`Base58Decode()`,
`Base62Decode()`,
`Base64Decode()`, `Base64URLDecode()`, `Base64RawDecode()`, `Base64RawURLDecode()`, `Base64SegmentDecode(paddingAllowed ...bool)`, `Base64DecodeWithEncoder(encoder string)`,
`Base85Encode()`,
`Base91Decode()`,
`Base100Decode()`,
`Basex2Decode()`, `Basex16Decode()`, `Basex62Decode()`, `BasexDecodeWithEncoder(encoder string)`,
`HexDecode()`,
`MorseITUDecode()`,
`SafeURLDecode()`,
`SerializeDecode()`,
`JSONDecode(dst any)`, `JSONIteratorDecode(dst any)`,
`GobDecode(dst any)`
有疑问加站长微信联系(非本文作者)