# README
GDOC
文档生成工具 GDOC(Generate Document Client)原理是通过扫描文件中的注解、标签 获取关键信息. 本工具依赖注解(Annotation),标签(Tag), 反射(Reflection).
关于依赖
- 注解
- 控制器
@RoutePrefix(path string)
- 路由前缀
- 接口方法
@Error(code int, message, description string)
- 错误码@Header(key, value, description message)
- 请求头@Ignore(on bool)
- 忽略文档@Request(struct string)
- 请求入参结构体@Response(struct string)
- 请求出参结构体/单条数据@ResponseData(struct string)
- 请求出参结构体/单条数据@ResponseList(struct string)
- 请求出参结构体/数据列列@ResponsePage(struct string)
- 请求出参结构体/带分页@Version(str string)
- 版本号
- 控制器
- 标签
desc
- 字段描述form
- 从POST表单中取值json
- 从JSON表单中取值label
- 字段标题/名称mock
- Mock数据值url
- 从URL参数中取值validate
- 字段格式校验
如何使用?
// Example code.
package main
import (
"github.com/fuyibing/gdoc/adapters/markdown"
"github.com/fuyibing/gdoc/base"
"github.com/fuyibing/gdoc/conf"
"github.com/fuyibing/gdoc/reflectors"
"github.com/fuyibing/gdoc/scanners"
)
func main() {
// 设置项目根目录.
conf.Path.SetBasePath("/home/applications/sketch")
// 设置控制器目录.
conf.Path.SetControllerPath("/app/controllers")
// 加载配置.
//
// 工具的执行时, 将读取此项目的的 gdoc.json 和 config/app.yaml
// 文件.
conf.Config.Load()
// 扫描文件.
//
// 扫描控制器目录下的GO源码, 然后从源码中匹配控制器
// 与接口方法列表.
scanners.Scanner.Scan()
// 反射结构.
ref := reflectors.New(base.Mapper)
ref.Configure()
if err := ref.Make(); err != nil {
return
}
// 调用适配器.
//
// 下列调用Markdown适配器, 触发后将把扫描结果与反射结果
// 格式化并生成MD文件.
markdown.New(base.Mapper).Run()
ref.Clean()
}