- fun gen [ts|go]:AST 扫描 BindService* 调用,临时生成 go test 辅助采集, 经 fun v1.3.7 公开 API 生成,产物与内置 GenCode 字节级一致(回归测试锁定) - fun run:热更新开发循环,先编译成功再切换,失败保留旧进程 - fun docs:浅色标准文档站——参数表/State 添加字段/请求 JSON 可编辑/ 响应格式化/NDJSON 流式逐行展示,反向代理 /cell 同源无 CORS - 元数据:TS 产物两遍解析重建(枚举/可空/流式工厂/嵌套引用全支持) - 纯标准库实现,零第三方依赖
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package main
|
|
|
|
// 元数据 JSON 契约:与 fun 核心库 meta.go 的导出结构一一对应。
|
|
// CLI 不依赖 fun 模块,仅消费该 JSON,保持零第三方依赖
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type FunMeta struct {
|
|
Services []MetaService `json:"services"`
|
|
}
|
|
|
|
type MetaService struct {
|
|
Name string `json:"name"`
|
|
Methods []MetaMethod `json:"methods"`
|
|
}
|
|
|
|
type MetaMethod struct {
|
|
Name string `json:"name"`
|
|
IsStream bool `json:"isStream"`
|
|
Void bool `json:"void,omitempty"`
|
|
DTO *MetaType `json:"dto,omitempty"`
|
|
Returns *MetaType `json:"returns,omitempty"`
|
|
}
|
|
|
|
type MetaType struct {
|
|
Kind string `json:"kind"` // int/bool/string/struct/slice/enum
|
|
Name string `json:"name,omitempty"`
|
|
Optional bool `json:"optional,omitempty"`
|
|
Fields []MetaField `json:"fields,omitempty"`
|
|
Elem *MetaType `json:"elem,omitempty"`
|
|
|
|
Names []string `json:"names,omitempty"`
|
|
DisplayNames []string `json:"displayNames,omitempty"`
|
|
}
|
|
|
|
type MetaField struct {
|
|
Name string `json:"name"`
|
|
Type *MetaType `json:"type"`
|
|
}
|
|
|
|
// loadMeta 从文件读取元数据
|
|
func loadMeta(path string) (*FunMeta, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var meta FunMeta
|
|
if err := json.Unmarshal(data, &meta); err != nil {
|
|
return nil, err
|
|
}
|
|
return &meta, nil
|
|
}
|