cmd.go 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package cmd
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/net/ghttp"
  6. "github.com/gogf/gf/v2/os/gcmd"
  7. "github.com/gogf/gf/v2/protocol/goai"
  8. "github.com/tiger1103/gfast/v3/internal/consts"
  9. "github.com/tiger1103/gfast/v3/internal/router"
  10. )
  11. var (
  12. Main = gcmd.Command{
  13. Name: "main",
  14. Usage: "main",
  15. Brief: "start http server",
  16. Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
  17. s := g.Server()
  18. s.Group("/", func(group *ghttp.RouterGroup) {
  19. router.BindController(group)
  20. })
  21. enhanceOpenAPIDoc(s)
  22. s.Run()
  23. return nil
  24. },
  25. }
  26. )
  27. func enhanceOpenAPIDoc(s *ghttp.Server) {
  28. openapi := s.GetOpenApi()
  29. openapi.Config.CommonResponse = ghttp.DefaultHandlerResponse{}
  30. openapi.Config.CommonResponseDataField = `Data`
  31. // API description.
  32. openapi.Info = goai.Info{
  33. Title: consts.OpenAPITitle,
  34. Description: consts.OpenAPIDescription,
  35. Contact: &goai.Contact{
  36. Name: consts.OpenAPIContactName,
  37. URL: consts.OpenAPIContactUrl,
  38. },
  39. }
  40. }