fix: 修正 Example 函数命名与输出注释位置,让 go vet / go test 恢复可用

go vet ./... 此前有 13 处失败, 导致 go test ./...(默认带 vet)根本跑不起来,
必须加 -vet=off。这是既存问题, 与实现改动无关。

命名问题(12 处): Example 函数名的前缀必须是包内真实存在的标识符。
  ExampleStructMap_*  -> ExampleR_*         (包里没有 StructMap)
  ExampleSet_*        -> ExampleR_Set_*     (Set 是 R 的方法, 不是包级函数)
  ExampleAppend_*     -> ExampleR_Append_*  (同上)
  ExampleSchema_Unmarshal -> ExampleSchema_unmarshalJSON
                                            (Schema 没有 Unmarshal 方法,
                                             这个例子演示的是 json.Unmarshal)

输出注释位置(1 处): ExampleR_Append_typeConversionError 的 // Output: 后面
还跟着一条注释, 违反"Output 必须是最后一个注释块"。因为格式不合法, Go 一直
没把它当输出例子比对 —— 里面写的期望输出其实是错的(与实际信息不符)也没被发现。
把注释挪到 defer 之前, 并把期望输出更正为真实的 panic 信息。
已验证: 故意改错期望输出现在会导致测试失败, 说明确实在比对了。

现在 go vet ./... 干净, go test ./... 无需 -vet=off 即可运行。
This commit is contained in:
2026-08-28 17:02:56 +08:00
parent e594e206f0
commit 659fc10bae
3 changed files with 28 additions and 28 deletions
+2 -2
View File
@@ -166,8 +166,8 @@ func ExampleSchema_Generate_complexNested() {
// user.contact.phone: N/A
}
// ExampleSchema_Unmarshal 演示直接使用 json.Unmarshal 创建 Schema
func ExampleSchema_Unmarshal() {
// ExampleSchema_unmarshalJSON 演示直接使用 json.Unmarshal 创建 Schema
func ExampleSchema_unmarshalJSON() {
// JSON Schema 字符串
jsonStr := `{
"name": {