代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。