Documentation
¶
Overview ¶
Package doc 文档格式
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
XMLName struct{} `xml:"api"`
Version Version `xml:"version,attr,omitempty"`
Method Method `xml:"method,attr"`
ID string `xml:"id,attr,omitempty"`
Path *Path `xml:"path"`
Summary string `xml:"summary,attr"`
Description Richtext `xml:"description,omitempty"`
Requests []*Request `xml:"request"` // 不同的 mimetype 可能会定义不同
Responses []*Request `xml:"response"`
Callback *Callback `xml:"callback,omitempty"`
Deprecated Version `xml:"deprecated,attr,omitempty"`
Headers []*Param `xml:"header,omitempty"`
Tags []string `xml:"tag,omitempty"`
Servers []string `xml:"server,omitempty"`
// contains filtered or unexported fields
}
API 表示 <api> 顶层元素
<api method="GET" version="1.1.1" id="get-user">
<path path="/users/{id}">
<param name="id" type="number" summary="summary" />
</path>
<tag>tag1</tag>
<server>admin</server>
...
</api>
func (*API) UnmarshalXML ¶
UnmarshalXML 实现 xml.Unmarshaler 接口
type Callback ¶
type Callback struct {
Method Method `xml:"method,attr"`
Path *Path `xml:"path,omitempty"`
Summary string `xml:"summary,attr,omitempty"`
Description Richtext `xml:"description,omitempty"`
Deprecated Version `xml:"deprecated,attr,omitempty"`
Reference string `xml:"ref,attr,omitempty"`
Responses []*Request `xml:"response,omitempty"`
Requests []*Request `xml:"request"` // 至少一个
Headers []*Param `xml:"header,omitempty"`
}
Callback 回调函数的定义
<Callback deprecated="1.1.1" method="GET">
<request status="200" mimetype="json" type="object">
<param name="name" type="string" />
<param name="sex" type="string">
<enum value="male">Male</enum>
<enum value="female">Female</enum>
</param>
<param name="age" type="number" />
</request>
</Callback>
func (*Callback) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Contact ¶
type Contact struct {
Name string `xml:"name,attr"`
URL string `xml:"url,omitempty"`
Email string `xml:"email,omitempty"`
}
Contact 描述联系方式
<contact name="name">
<url>https://example.com</url>
<email>name@example.com</email>
</contact>
func (*Contact) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Doc ¶
type Doc struct {
XMLName struct{} `xml:"apidoc"`
// 程序的版本号
//
// 同时也作为文档格式的版本号。客户端可以依此值确定文档格式。
// 仅用于输出,文档中不需要指定此值。
APIDoc string `xml:"apidoc,attr,omitempty"`
// 文档内容的区域信息
// 如果存在此值,客户端应该尽量根据此值显示相应的界面语言。
Lang string `xml:"lang,attr,omitempty"`
// 文档的图标
//
// 如果采用默认的 xsl 转换,会替换掉页面上的图标和 favicon 图标
Logo string `xml:"logo,attr,omitempty"`
Created string `xml:"created,attr,omitempty"` // 文档的生成时间
Version Version `xml:"version,attr,omitempty"` // 文档的版本
Title string `xml:"title"`
Description Richtext `xml:"description"`
Contact *Contact `xml:"contact,omitempty"`
License *Link `xml:"license,omitempty"` // 版本信息
Tags []*Tag `xml:"tag,omitempty"` // 所有的标签
Servers []*Server `xml:"server,omitempty"`
Apis []*API `xml:"api,omitempty"`
// 表示所有 API 都有可能返回的内容
Responses []*Request `xml:"response,omitempty"`
// contains filtered or unexported fields
}
Doc 文档
type Enum ¶
type Enum struct {
Deprecated Version `xml:"deprecated,attr,omitempty"`
Value string `xml:"value,attr"`
Summary string `xml:"summary,attr,omitempty"`
Description string `xml:",innerxml"`
}
Enum 表示枚举值
<enum value="male">男性</enum> <enum value="female">女性</enum>
func (*Enum) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Example ¶
type Example struct {
Description string `xml:"description,omitempty"`
Mimetype string `xml:"mimetype,attr"`
Content string `xml:",cdata"`
}
Example 示例代码
func (*Example) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Link ¶
Link 表示一个链接
<link url="https://example.com">text</link>
func (*Link) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Method ¶
type Method string
Method 表示请求方法
func (Method) MarshalXML ¶
MarshalXML xml.Marshaler
func (Method) MarshalXMLAttr ¶
MarshalXMLAttr xml.MarshalerAttr
func (*Method) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Param ¶
type Param struct {
Name string `xml:"name,attr"`
Type Type `xml:"type,attr"`
Deprecated Version `xml:"deprecated,attr,omitempty"`
Default string `xml:"default,attr,omitempty"`
Optional bool `xml:"optional,attr,omitempty"`
Array bool `xml:"array,attr,omitempty"`
Items []*Param `xml:"param,omitempty"`
Reference string `xml:"ref,attr,omitempty"`
Summary string `xml:"summary,attr,omitempty"`
Enums []*Enum `xml:"enum,omitempty"`
Description Richtext `xml:"description,omitempty"`
}
Param 表示参数类型
<param name="user" deprecated="1.1.1" type="object" array="true">
<param name="name" type="string" />
<param name="sex" type="string">
<enum value="male">Male</enum>
<enum value="female">Female</enum>
</param>
<param name="age" type="number" />
</param>
func (*Param) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Path ¶
type Path struct {
Path string `xml:"path,attr"`
Params []*Param `xml:"param,omitempty"`
Queries []*Param `xml:"query,omitempty"`
Reference string `xml:"ref,attr,omitempty"`
}
Path 路径信息
<path path="/users/{id}">
<param name="id" type="number" summary="summary" />
<query name="page" type="number" summary="page" default="1" />
</path>
func (*Path) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Request ¶
type Request struct {
// 一般无用,但是用于描述 XML 对象时,可以用来表示顶层元素的名称
Name string `xml:"name,attr,omitempty"`
Type Type `xml:"type,attr"` // Request 中默认为 None
Deprecated Version `xml:"deprecated,attr,omitempty"`
Enums []*Enum `xml:"enum,omitempty"`
Array bool `xml:"array,attr,omitempty"`
Items []*Param `xml:"param,omitempty"`
Reference string `xml:"ref,attr,omitempty"`
Summary string `xml:"summary,attr,omitempty"`
Status Status `xml:"status,attr,omitempty"`
Mimetype string `xml:"mimetype,attr"`
Examples []*Example `xml:"example,omitempty"`
Headers []*Param `xml:"header,omitempty"` // 当前独有的报头,公用的可以放在 API 中
Description Richtext `xml:"description,omitempty"`
}
Request 请求内容
func (*Request) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Richtext ¶
type Richtext struct {
Text string `xml:",innerxml"`
}
Richtext 富文本内容
func (Richtext) MarshalXML ¶
MarshalXML xml.Marshaler
type Server ¶
type Server struct {
Name string `xml:"name,attr"` // 字面名称,需要唯一
URL string `xml:"url,attr"`
Deprecated Version `xml:"deprecated,attr,omitempty"`
Description string `xml:",innerxml"`
}
Server 服务信息
<server name="tag1" deprecated="1.1.1" url="api.example.com/admin">description</server>
func (*Server) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Status ¶
type Status int
Status 表示 HTTP 状态码
func (Status) MarshalXML ¶
MarshalXML xml.Marshaler
func (Status) MarshalXMLAttr ¶
MarshalXMLAttr xml.MarshalerAttr
func (*Status) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Tag ¶
type Tag struct {
Name string `xml:"name,attr"` // 标签的唯一 ID
Title string `xml:"title,attr"` // 显示的名称
Deprecated Version `xml:"deprecated,attr,omitempty"`
}
Tag 标签内容
<tag name="tag1" deprecated="1.1.1">description</tag>
func (*Tag) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Type ¶
type Type uint8
Type 表示数据类型
func (Type) MarshalXML ¶
MarshalXML xml.Marshaler
func (Type) MarshalXMLAttr ¶
MarshalXMLAttr xml.MarshalerAttr
func (*Type) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler
type Version ¶
type Version string
Version 版本号
func (Version) MarshalXML ¶
MarshalXML xml.Marshaler
func (Version) MarshalXMLAttr ¶
MarshalXMLAttr xml.MarshalerAttr
func (*Version) UnmarshalXML ¶
UnmarshalXML xml.Unmarshaler