1 Star 0 Fork 0

go-better/go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
route.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
bughou 提交于 3年前 . add goa
package docs
import (
"bytes"
"html"
"reflect"
"regexp"
"strings"
"gitee.com/go-better/dev/type/structs"
)
type Route struct {
req, resp reflect.Type
}
func (r *Route) Parse(handler interface{}) bool {
typ := reflect.TypeOf(handler)
if typ.NumIn() != 2 {
return false
}
r.req, r.resp = typ.In(0), typ.In(1).Elem()
return true
}
func (r *Route) Doc(method, fullPath string) []byte {
buf := bytes.NewBufferString(
"# " + r.Title() + "<br>" + r.MethodPath(method, fullPath) + "\n",
)
r.Desc(buf)
r.Param(buf, fullPath)
r.Query(buf)
r.Header(buf)
r.Body(buf)
r.RespHeader(buf)
r.RespBody(buf)
r.RespError(buf)
return buf.Bytes()
}
func (r *Route) MethodPath(method, fullPath string) string {
return method + " " + html.EscapeString(fullPath)
}
var whitespaceRegexp = regexp.MustCompile(`\s+`)
// extract comment from struct field tags
func getComment(tag reflect.StructTag) string {
tagStr := string(tag)
comment, _ := structs.LookupTag(tagStr, `comment`)
if comment == `` {
comment, _ = structs.LookupTag(tagStr, `c`)
}
if comment != `` {
comment = strings.TrimSpace(comment)
}
if comment != `` {
comment = whitespaceRegexp.ReplaceAllString(comment, " ")
}
return comment
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-better/go.git
git@gitee.com:go-better/go.git
go-better
go
go
d31700df43a9

搜索帮助