将go的结构定义转化为markdown 表格(帮助快速生产文档)
Type2md - Golang Type To Markdown
github.com/eleztian/type2md
通过ast解析 将golang 的结构定义转化为markdown 表格。
支持将golang 的数据类型定义转化为markdown 表格
- 支持自定义 struct tag
- 支持注释解析
- 支持默认值定义
- 支持是否必填
- 支持外部mod 类型引用解析。
- 表格类型支持跳转
Usage
安装
$ go install github.com/eleztian/type2md
使用
$ type2md -h
Usage of type2md:
-f string
file path
-t string
file title
-tag string
struct tag name (default "json")
-v show version
Example
package test
import "github.com/eleztian/type2md/test/ext"
//go:generate type2md -f ../docs/doc_config.md github.com/eleztian/type2md/test Config
// Config doc.
type Config struct {
Pre ext.Hook
Post *ext.Hook
Servers map[string]struct {
Host string `json:"host,omitempty"`
Port int `json:"port" enums:"22,65522" require:"false"`
} `json:"servers"` // server list
InlineStruct `json:",inline"` // inline struct
Slice []string // sss
MapData map[string]map[int]*OtherStruct
ArrayData [][2]string `json:"array_data"`
C []interface{} // slice interface{}
}
// InlineStruct inline struct.
type InlineStruct struct {
A string `json:"a"` // inline struct field a
}
// OtherStruct other struct
// this is use for test.
type OtherStruct struct {
A string `json:"a" require:"true" default:"default value"`
B [][2]ext.Mode `json:"b"` // array string
C map[string]interface{} `json:"c"` // map[string]interface{}
D *OtherStruct `json:"d"` // nested struct
}
执行下列命令
$ go generate ./...
2022/10/28 23:56:16 Current Module: github.com/eleztian/type2md
2022/10/28 23:56:16 start generate github.com/eleztian/type2md/test.Config
2022/10/28 23:56:16 start to save to ../docs/doc_config.md
得到下面的文档:
Config Doc
Config doc.
Key | Type | Require | Default | Describe |
---|---|---|---|---|
Pre | true | |||
Post | true | |||
servers.{string}.host | string | false | ||
servers.{string}.port | int | false |
| |
a | string | true | inline struct field a. | |
Slice.[] | string | true | sss. | |
MapData.{string}.{int}. | true | |||
array_data.[] .[2] | string | true | ||
C.[] | any | true | slice interface{}. |
ext.Hook
Hook hook config.
Key | Type | Require | Default | Describe |
---|---|---|---|---|
name | string | false | example | hook name. |
commands.[] | string | true | command list. | |
envs.{string} | string | true | env key map. | |
mode | true | 1 | run mode. |
OtherStruct
OtherStruct other struct
this is use for test.
Key | Type | Require | Default | Describe |
---|---|---|---|---|
a | string | true | default value | |
b.[] .[2] | true | array string. | ||
c.{string} | any | true | map[string] interface{}. | |
d | true | nested struct. |
ext.Mode
Type: int
Mode mode define.
Enum Value | Describe |
---|---|
1 | mode q. |
2 | mode a. |
github.com/eleztian/type2md/test.Config
GENERATED BY THE COMMAND type2md
相关文章
- 【愚公系列】2022年07月 Go教学课程 028-函数小结案例(通讯录)
- go富集分析和kegg富集分析的区别_非模式生物怎么做GO富集
- 4.Go编程快速入门学习
- Centos Go环境搭建「建议收藏」
- 2022-08-27:以下go语言代码输出什么?A:[0];B:panic;C:7;D:不清楚。package mainimpo
- Golang语言情怀--第101期 区块链技术-以太坊公链NFT图片去中心化存储-第2节:go语言实现IPFS存储demo
- GO 2,我们来了——2018/11/29
- Go 模块 verifying xxx/go.mod: checksum mismatch 问题处理
- 周末轻松点,掌握Go基础知识,直观感受和Java的区别
- go: 官方提供的泛形约束(constraints)
- Go-标准库-fmt(一)
- Go-包管理-go get(二)
- Go-包管理-go install
- AI实现代码转换,Python转Java,Java转Go不再困难?
- Go语言方法和接收器
- 编程新精英:Go语言 Redis开发(go语言redis开发)
- Go 公布 2.0 设计草案:规模化和扩展性、支持泛型
- Linux上构建Go开发环境(linux安装go环境)
- Go语言连接Oracle数据库实战(go连接oracle)
- 部署Linux下快速部署Go环境(go环境linux)
- SQL Server快速上手GO!(sqlserver go)
- 徒手用Go编写Redis迈向新技术世界的旅程(徒手用go写个redis)
- MySQL中使用Go语言的好处(mysql中go什么)
- 踏上oracle编程之路,Go(go oracle编程)
- 学习Oracle Go了解信息技术世界(oracle go的用法)
- GO语言标准错误处理机制error用法实例
- go语言环境搭建简述