Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
45
AI.md
45
AI.md
@ -9,45 +9,14 @@
|
|||||||
3. **IntEncoder 集成**:所有整数进制编码、填充、混淆、哈希操作均通过 `IntEncoder` 实例或其导出的封装函数进行。
|
3. **IntEncoder 集成**:所有整数进制编码、填充、混淆、哈希操作均通过 `IntEncoder` 实例或其导出的封装函数进行。
|
||||||
4. **安全链路**:优先使用基于字节切片的 API,减少不必要的内存分配与 string 转换。
|
4. **安全链路**:优先使用基于字节切片的 API,减少不必要的内存分配与 string 转换。
|
||||||
|
|
||||||
## 🛠 API Reference
|
## 🛠 关键 API 设计约定
|
||||||
|
|
||||||
### 基础编解码 (Hex/Base64)
|
| 类型 | 语义 API | 静默 API (Quiet) |
|
||||||
- `func Hex(data []byte) []byte`:将数据转换为 Hex 编码的字节切片。
|
| :--- | :--- | :--- |
|
||||||
- `func HexToString(data []byte) string`:将数据转换为 Hex 编码的字符串。
|
| **Hex** | `Hex/UnHex` | `MustUnHex/MustUnHexFromString` |
|
||||||
- `func MustUnHex(data []byte) []byte`:解码 Hex,出错时返回空字节切片。
|
| **Base64** | `Base64/UnBase64` | `MustUnBase64/MustUnBase64FromString` |
|
||||||
- `func MustUnHexFromString(data string) []byte`:解码 Hex 字符串,出错时返回空字节切片。
|
| **IntEncoder** | `EncodeInt/AppendInt/FillInt/ExchangeIntInt/DecodeInt/HashInt` | - |
|
||||||
- `func UnHex(data []byte) ([]byte, error)`:解码 Hex。
|
| **Web** | `UrlEncode/HtmlEscape` | `MustUnUrlEncode/MustUnHtmlEscape` |
|
||||||
- `func Base64(data []byte) []byte`:将数据转换为 Base64 编码的字节切片。
|
|
||||||
- `func Base64ToString(data []byte) string`:将数据转换为 Base64 编码的字符串。
|
|
||||||
- `func UrlBase64(data []byte) []byte`:将数据转换为 URL 安全的 Base64 编码的字节切片。
|
|
||||||
- `func UrlBase64ToString(data []byte) string`:将数据转换为 URL 安全的 Base64 编码的字符串。
|
|
||||||
- `func MustUnBase64(data []byte) []byte`:解码 Base64,出错时返回空字节切片。
|
|
||||||
- `func MustUnBase64FromString(data string) []byte`:解码 Base64 字符串,出错时返回空字节切片。
|
|
||||||
- `func MustUnUrlBase64(data []byte) []byte`:解码 URL Base64,出错时返回空字节切片。
|
|
||||||
- `func MustUnUrlBase64FromString(data string) []byte`:解码 URL Base64 字符串,出错时返回空字节切片。
|
|
||||||
- `func UnBase64(data []byte) ([]byte, error)`:解码 Base64。
|
|
||||||
- `func UnUrlBase64(data []byte) ([]byte, error)`:解码 URL Base64。
|
|
||||||
|
|
||||||
### Web 编码 (URL/HTML)
|
|
||||||
- `func UrlEncode(data []byte) string`:URL 编码。
|
|
||||||
- `func MustUnUrlEncode(data string) []byte`:URL 解码,出错时返回空字节切片。
|
|
||||||
- `func HtmlEscape(data []byte) string`:HTML 转义。
|
|
||||||
- `func MustUnHtmlEscape(data string) string`:HTML 反转义。
|
|
||||||
- `func Utf8Valid(data []byte) bool`:校验 UTF-8。
|
|
||||||
|
|
||||||
### 整数编码 (IntEncoder)
|
|
||||||
- `func NewIntEncoder(digits string, radix uint8) (*IntEncoder, error)`:创建自定义编码器。
|
|
||||||
- `func EncodeInt(u uint64) []byte`:默认编码整数。
|
|
||||||
- `func AppendInt(buf []byte, u uint64) []byte`:默认追加整数。
|
|
||||||
- `func DecodeInt(buf []byte) uint64`:默认解码整数。
|
|
||||||
- `func ExchangeInt(buf []byte) []byte`:默认置换混淆。
|
|
||||||
- `func HashInt(data []byte, key []byte) []byte`:默认 HMAC-SHA512 哈希。
|
|
||||||
- `func (enc *IntEncoder) EncodeInt(u uint64) []byte`
|
|
||||||
- `func (enc *IntEncoder) AppendInt(buf []byte, u uint64) []byte`
|
|
||||||
- `func (enc *IntEncoder) FillInt(buf []byte, length int) []byte`:填充至指定长度。
|
|
||||||
- `func (enc *IntEncoder) ExchangeInt(buf []byte) []byte`
|
|
||||||
- `func (enc *IntEncoder) HashInt(data []byte, key []byte) []byte`
|
|
||||||
- `func (enc *IntEncoder) DecodeInt(buf []byte) uint64`
|
|
||||||
|
|
||||||
## 🧩 典型模式 (Best Practices)
|
## 🧩 典型模式 (Best Practices)
|
||||||
|
|
||||||
|
|||||||
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2026 ssgo
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@ -1,7 +1,3 @@
|
|||||||
# 关于本项目
|
|
||||||
|
|
||||||
本项目完全由 AI 维护。代码源自 github.com/ssgo/u 的重构。
|
|
||||||
|
|
||||||
# @go/encoding
|
# @go/encoding
|
||||||
|
|
||||||
`@go/encoding` 是一个为“极简、安全、无摩擦”业务开发设计的编解码工具库。它统一了二进制数据与文本处理的 API 语义,通过静默处理错误与基于字节的零拷贝设计,极大降低了业务逻辑中的错误处理心智负担。
|
`@go/encoding` 是一个为“极简、安全、无摩擦”业务开发设计的编解码工具库。它统一了二进制数据与文本处理的 API 语义,通过静默处理错误与基于字节的零拷贝设计,极大降低了业务逻辑中的错误处理心智负担。
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user