mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
This commit is contained in:
@ -31,7 +31,42 @@ func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error)
|
||||
return
|
||||
}
|
||||
|
||||
// upload file request
|
||||
type UploadReq struct {
|
||||
g.Meta `path:"/upload" method:"POST" tags:"Upload" mime:"multipart/form-data" summary:"上传文件"`
|
||||
Files []*ghttp.UploadFile `json:"files" type:"file" dc:"选择上传多文件"`
|
||||
File *ghttp.UploadFile `p:"file" type:"file" dc:"选择上传文件"`
|
||||
Msg string `dc:"消息"`
|
||||
}
|
||||
|
||||
// upload file response
|
||||
type UploadRes struct {
|
||||
FilesName []string `json:"files_name"`
|
||||
FileName string `json:"file_name"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
// upload file
|
||||
func (Hello) Upload(ctx context.Context, req *UploadReq) (res *UploadRes, err error) {
|
||||
g.Log().Debugf(ctx, `receive say: %+v`, req)
|
||||
res = &UploadRes{
|
||||
Msg: req.Msg,
|
||||
}
|
||||
if req.File != nil {
|
||||
res.FileName = req.File.Filename
|
||||
}
|
||||
if len(req.Files) > 0 {
|
||||
var filesName []string
|
||||
for _, file := range req.Files {
|
||||
filesName = append(filesName, file.Filename)
|
||||
}
|
||||
res.FilesName = filesName
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
// MySwaggerUITemplate is the custom Swagger UI template.
|
||||
MySwaggerUITemplate = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@ -55,6 +90,20 @@ const (
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
// OpenapiUITemplate is the OpenAPI UI template.
|
||||
OpenapiUITemplate = `
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="openapi-ui-container" spec-url="{SwaggerUIDocUrl}" theme="light"></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@latest/lib/openapi-ui.umd.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
)
|
||||
|
||||
@ -67,5 +116,6 @@ func main() {
|
||||
)
|
||||
})
|
||||
s.SetSwaggerUITemplate(MySwaggerUITemplate)
|
||||
// s.SetSwaggerUITemplate(OpenapiUITemplate) // files support
|
||||
s.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user