Compare commits

...

2 Commits
v1.0.0 ... main

Author SHA1 Message Date
AI Engineer
b776a4e2c2 AI: 更新文档索引至 v1.0.3 2026-04-24 16:58:29 +08:00
d0f9cdbec3 docs: add MIT license and update README origin info (AI) 2026-04-22 14:33:03 +08:00
3 changed files with 63 additions and 7 deletions

45
AI.md
View File

@ -9,14 +9,45 @@
3. **IntEncoder 集成**:所有整数进制编码、填充、混淆、哈希操作均通过 `IntEncoder` 实例或其导出的封装函数进行。
4. **安全链路**:优先使用基于字节切片的 API减少不必要的内存分配与 string 转换。
## 🛠 关键 API 设计约定
## 🛠 API Reference
| 类型 | 语义 API | 静默 API (Quiet) |
| :--- | :--- | :--- |
| **Hex** | `Hex/UnHex` | `MustUnHex/MustUnHexFromString` |
| **Base64** | `Base64/UnBase64` | `MustUnBase64/MustUnBase64FromString` |
| **IntEncoder** | `EncodeInt/AppendInt/FillInt/ExchangeIntInt/DecodeInt/HashInt` | - |
| **Web** | `UrlEncode/HtmlEscape` | `MustUnUrlEncode/MustUnHtmlEscape` |
### 基础编解码 (Hex/Base64)
- `func Hex(data []byte) []byte`:将数据转换为 Hex 编码的字节切片。
- `func HexToString(data []byte) string`:将数据转换为 Hex 编码的字符串。
- `func MustUnHex(data []byte) []byte`:解码 Hex出错时返回空字节切片。
- `func MustUnHexFromString(data string) []byte`:解码 Hex 字符串,出错时返回空字节切片。
- `func UnHex(data []byte) ([]byte, error)`:解码 Hex。
- `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)

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
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.

View File

@ -1,3 +1,7 @@
# 关于本项目
本项目完全由 AI 维护。代码源自 github.com/ssgo/u 的重构。
# @go/encoding
`@go/encoding` 是一个为“极简、安全、无摩擦”业务开发设计的编解码工具库。它统一了二进制数据与文本处理的 API 语义,通过静默处理错误与基于字节的零拷贝设计,极大降低了业务逻辑中的错误处理心智负担。