1 Star 1 Fork 2

kristas / booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_inject_extra_controller.go 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-10-22 22:58 . feat: add annotation
package api_test
import (
"context"
"gitee.com/kristas/booting-go/framework"
file2 "gitee.com/kristas/booting-go/framework/common/util/file"
"gitee.com/kristas/booting-go/framework/core/statement/types"
"gitee.com/kristas/booting-go/framework/web/rest"
model2 "gitee.com/kristas/booting-go/internal/demo/model"
"mime/multipart"
"net/http"
)
func init() {
framework.Component(new(TestInjectExtraController))
}
type TestInjectExtraController struct {
types.Controller `group:"/test/inject/extra"`
testForm rest.POST `url:"/form" param:"[Int,Float,Bool,String,Map form]"`
testMultipart rest.POST `url:"/multipart" param:"[file,file,file multipart]"`
testContext rest.GET `url:"/context" param:"[c context]"`
testReqNResp rest.GET `url:"/request_response" param:"[r request,w response]"`
testStream rest.POST `url:"/stream" param:"[s stream]"`
}
func (r *TestInjectExtraController) TestPath(i int, f float64, bl bool, s string) interface{} {
return map[string]interface{}{
"source": "path",
"int": i,
"float": f,
"bool": bl,
"string": s,
}
}
func (r *TestInjectExtraController) TestQuery(i int, f float64, bl bool, s string, account model2.Account) interface{} {
return map[string]interface{}{
"source": "query",
"int": i,
"float": f,
"bool": bl,
"string": s,
"struct": account,
}
}
func (r *TestInjectExtraController) TestBody(account model2.Account) interface{} {
return map[string]interface{}{
"source": "body",
"struct": account,
}
}
func (r *TestInjectExtraController) TestForm(i int, f float64, bl bool, s string, m map[string][]string) interface{} {
return map[string]interface{}{
"source": "form",
"int": i,
"float": f,
"bool": bl,
"string": s,
"map": m,
}
}
func (r *TestInjectExtraController) TestMultipart(file multipart.File, header *multipart.FileHeader, value string) interface{} {
return map[string]interface{}{
"file": value,
"size": file2.FormatFileSize(header.Size),
"fileName": header.Filename,
}
}
func (r *TestInjectExtraController) TestHeader(token string) string {
return "token is " + token
}
func (r *TestInjectExtraController) TestContext(c context.Context) string {
time, _ := c.Deadline()
return time.Format(http.TimeFormat)
}
func (r *TestInjectExtraController) TestReqNResp(req *http.Request, w http.ResponseWriter) {
w.Write([]byte(req.Host + req.RequestURI))
}
func (r *TestInjectExtraController) TestStream(s []byte) interface{} {
return string(s)
}
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.4.4

搜索帮助