Compare commits

...

2 Commits
v1.0.2 ... main

Author SHA1 Message Date
AI Engineer
88c22e7ca7 AI: 更新文档索引至 v1.0.3 2026-04-24 16:58:23 +08:00
b955022fe7 docs: add MIT license and update README origin info (AI) 2026-04-22 14:33:02 +08:00
4 changed files with 36 additions and 21 deletions

30
AI.md
View File

@ -1,6 +1,6 @@
# AI Coding Context: @go/convert # AI Coding Context: @go/convert
本索引供 AI 模型理解 `@go/convert`设计逻辑,以生成符合本项目“意图优先、零摩擦”哲学的代码。 本索引供 AI 模型理解 `@go/convert` 的逻辑,以生成符合本项目“意图优先、零摩擦”哲学的代码。
## 🤖 AI 行为准则 ## 🤖 AI 行为准则
@ -9,35 +9,25 @@
3. **利用键名容忍度**:在处理不可控的外部数据时,无需担心键名格式(驼峰、蛇形等),`convert.To` 会自动匹配。 3. **利用键名容忍度**:在处理不可控的外部数据时,无需担心键名格式(驼峰、蛇形等),`convert.To` 会自动匹配。
4. **无视指针层级**:在编写调用代码时,无需手动解引用或取地址以匹配类型,`convert` 内部会自动穿透处理。 4. **无视指针层级**:在编写调用代码时,无需手动解引用或取地址以匹配类型,`convert` 内部会自动穿透处理。
## 🛠 关键 API 逻辑约定 ## 🛠 API Reference
| 函数 | 逻辑特征 | ### 核心转换函数
| :--- | :--- | - `func To(from, to any)`:支持任意可能的类型深度转换,`to` 必须为指针。
| `To(from, to)` | **主入口**。要求 `to` 必须为指针。核心逻辑是根据 `to` 的类型强力揉捏 `from`。 |
| `Convert(from, to)` | `To` 的别名。 | ### 结构体分析
| `FlatStruct(data)` | 获取结构体的扁平化元信息(导出字段/方法)。 | - `func FlatStruct(data any) *StructInfo`:平展结构体(仅导出字段/方法)。
- `func FlatStructWithUnexported(data any) *StructInfo`:平展结构体(包含未导出字段/方法)。
## 🧩 典型模式 (Best Practices) ## 🧩 典型模式 (Best Practices)
* **❌ 不推荐 (Standard Go)**:
```go
// 手动映射字段,且对格式敏感
u.UserID = m["user_id"].(int)
```
* **✅ 推荐 (@go/convert)**: * **✅ 推荐 (@go/convert)**:
```go ```go
// 自动匹配任何格式的键名 // 自动匹配任何格式的键名
convert.To(m, &u) convert.To(from, &u)
``` ```
* **❌ 不推荐 (Standard Go)**:
```go
// 手动处理单值转切片
var dest []int
dest = append(dest, src)
```
* **✅ 推荐 (@go/convert)**: * **✅ 推荐 (@go/convert)**:
```go ```go
// 自动包装 // 自动包装单值至切片
convert.To(src, &dest) convert.To(src, &dest)
``` ```

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/convert # @go/convert
`@go/convert` 是一个为“零摩擦”数据映射设计的深度转换库。它的核心哲学是**意图优先**:通过目标对象的类型推断用户的需求,并尽力抹平输入数据与目标形状之间的鸿沟。 `@go/convert` 是一个为“零摩擦”数据映射设计的深度转换库。它的核心哲学是**意图优先**:通过目标对象的类型推断用户的需求,并尽力抹平输入数据与目标形状之间的鸿沟。

2
go.mod
View File

@ -3,6 +3,6 @@ module apigo.cc/go/convert
go 1.25.0 go 1.25.0
require ( require (
apigo.cc/go/cast v1.0.2 apigo.cc/go/cast v1.0.3
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )