autodoc

package module
v0.0.0-...-10a0dff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2018 License: MIT Imports: 16 Imported by: 1

README

echo-autodoc

Automatically generate documents for Golang echo web framework.

See example for more detail.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// c.JSON 时,若传入的数据有零值,可以将其递归地填充为非零值(数值填充成 1,字符串填充成 "1",布尔值依然为 false)
	FillZeroValue = false

	SkipGen = "[skip gen]"

	// 当返回值不为 200 时,打印 warning 信息
	WarningWhenNotStatusOK = true

	// 字段缺少描述时打印 warning 信息
	WarningMissingFields = true
)

杂项配置

View Source
var (
	DefaultMarkdownHeader = `# 接口文档

## HTTP 接口`
	DefaultMarkdownFooter = ""

	DefaultFormFileDesc = "上传的文件"
)

Markdown 相关配置

View Source
var (
	DefaultCookie = http.Cookie{Value: "1"}

	DefaultGetReturn        interface{} = 1
	DefaultQueryParamReturn             = "1"
	DefaultFormValueReturn              = "1"

	DefaultMultipartFileHeader        = multipart.FileHeader{Filename: "example.txt", Size: 1}
	DefaultMultipartFileHeaderContent = []byte("A")
)

默认 echo 操作返回值 若要精确设置,见下方的 AddCustomGetReturn 等

View Source
var (
	EmptyContextJSONer     = &emptyContextJSON{}
	ErrorCodeContextJSONer = &errorCodeContextJSON{1000}
)
View Source
var (
	DefaultTime = time.Date(2010, 11, 22, 15, 16, 17, 0, time.Local)
)

Functions

func AddCustomContextGetReturn

func AddCustomContextGetReturn(key string, ret interface{})

func AddCustomFormValueReturn

func AddCustomFormValueReturn(name string, str string)

func AddCustomGetReturn

func AddCustomGetReturn(key string, ret interface{})

func AddCustomGoTypeToJSONType

func AddCustomGoTypeToJSONType(goType string, jsonType string)

func AddCustomQueryParamReturn

func AddCustomQueryParamReturn(name string, str string)

func FillEmptyValuesOfStruct

func FillEmptyValuesOfStruct(structVal reflect.Value, intVal int64, uintVal uint64, floatVal float64, stringVal string)

只能修改 public 字段

func FillStruct

func FillStruct(structPtr interface{})

只能修改 public 字段,structPtr 不是 struct 指针时无效

func ModifyFileHeaderContent

func ModifyFileHeaderContent(fh *multipart.FileHeader, content []byte)

func NewAPICollector

func NewAPICollector() *apiCollector

handler_test.go 中调用

func SetContextGetParams

func SetContextGetParams(params ...Param)

func SetFormParams

func SetFormParams(params ...Param)

func SetGloablResponseJSONParams

func SetGloablResponseJSONParams(params ...Param)

globalResponseJSONParams 为所有返回的 JSON 都会有的字段 同时会设置 ignoredResponseJSONParams

func SetIgnoredResponseJSONParams

func SetIgnoredResponseJSONParams(params ...Param)

解析返回的 JSON 时,忽略这些字段

func SetPostJSONParams

func SetPostJSONParams(params ...Param)

func SetQueryParams

func SetQueryParams(params ...Param)

func SetResponseJSONParams

func SetResponseJSONParams(params ...Param)

Types

type ContextJSON

type ContextJSON interface {
	BeforeJSON(code int, i interface{})
	AfterJSON(code int, i interface{})
}
var (
	ContextJSONer ContextJSON = ErrorCodeContextJSONer
)

type GroupInterface

type GroupInterface interface {
	Group(prefix string, middleware ...echo.MiddlewareFunc) GroupInterface
	Use(middleware ...echo.MiddlewareFunc)
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

func NewGroup

func NewGroup(e *echo.Echo) GroupInterface

handler.go 中调用

type GroupInterfaceFull

type GroupInterfaceFull interface {
	Use(m ...echo.MiddlewareFunc)
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	Any(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	Match(methods []string, path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) []*echo.Route
	Group(prefix string, m ...echo.MiddlewareFunc) GroupInterface
	Static(prefix, root string)
	File(path, file string)
	Add(method, path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

由于 Group 方法返回的类型和调用者相同,只能将所有方法提出到一个 interface

type Param

type Param struct {
	Type string
	Name string
	Desc string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL