|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
|
|
"github.com/gogf/gf/v2/net/goai"
|
|
|
|
"github.com/gogf/gf/v2/os/gcmd"
|
|
|
|
"log"
|
|
|
|
"tyj_admin/internal/consts"
|
|
|
|
"tyj_admin/internal/router"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Main = gcmd.Command{
|
|
|
|
Name: "main",
|
|
|
|
Usage: "main",
|
|
|
|
Brief: "start http server",
|
|
|
|
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
|
|
|
s := g.Server()
|
|
|
|
s.Group("/", func(group *ghttp.RouterGroup) {
|
|
|
|
router.BindController(group)
|
|
|
|
router.BindAnotherController(group)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.BindHandler("/upload_file", func(r *ghttp.Request) {
|
|
|
|
log.Printf("upload_file >>>>>> filename: %s", r.GetQuery("filename"))
|
|
|
|
r.Response.ServeFileDownload("./download/" + r.GetQuery("filename").String())
|
|
|
|
})
|
|
|
|
|
|
|
|
s.BindHandler("/download_file", func(r *ghttp.Request) {
|
|
|
|
log.Printf("download_file >>>>>> filename: %s", r.GetQuery("filename"))
|
|
|
|
r.Response.ServeFileDownload("./download/" + r.GetQuery("filename").String())
|
|
|
|
})
|
|
|
|
enhanceOpenAPIDoc(s)
|
|
|
|
//s.EnableHTTPS("server.crt", "server.key")
|
|
|
|
s.Run()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func enhanceOpenAPIDoc(s *ghttp.Server) {
|
|
|
|
openapi := s.GetOpenApi()
|
|
|
|
openapi.Config.CommonResponse = ghttp.DefaultHandlerResponse{}
|
|
|
|
openapi.Config.CommonResponseDataField = `Data`
|
|
|
|
|
|
|
|
// API description.
|
|
|
|
openapi.Info = goai.Info{
|
|
|
|
Title: consts.OpenAPITitle,
|
|
|
|
Description: consts.OpenAPIDescription,
|
|
|
|
Contact: &goai.Contact{
|
|
|
|
Name: consts.OpenAPIContactName,
|
|
|
|
URL: consts.OpenAPIContactUrl,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|