Documentation ¶
Overview ¶
Package mock 根据 doc 生成 mock 数据
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
func Load(h *core.MessageHandler, path core.URI, indent, imageURL string, servers map[string]string, gen *GenOptions) (http.Handler, error)
Load 从本地或是远程加载文档内容
func New ¶
func New(msg *core.MessageHandler, d *ast.APIDoc, indent, imageURL string, servers map[string]string, gen *GenOptions) (http.Handler, error)
New 声明 Mock 对象
msg 用于处理各类输出消息,仅在 ServeHTTP 中的消息才输出到 msg; d doc.APIDoc 实例,调用方需要保证该数据类型的正确性; indent 缩进字符串; servers 用于指定 d.Servers 中每一个服务对应的路由前缀; gen 生成随机数据的函数;
Types ¶
type GenOptions ¶
type GenOptions struct { // 返回一个随机的数值 // // 可以是浮点和整数类型。 Number func(p *ast.Param) interface{} // 返回一个随机长度的字符串 String func(p *ast.Param) string // 返回一个随机的布尔值 Bool func() bool // 返回一个随机的数值 // // 该数值被用于声明 slice 长度,所以必须为正整数。 SliceSize func() int // 返回一个介于 [0, max] 之间的数值 // // 该数值被用于从数组中获取其中的某个元素。 Index func(max int) int }
GenOptions 生成随机数据的函数
Click to show internal directories.
Click to hide internal directories.