cmd.go 995 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/net/goai"
  7. "github.com/gogf/gf/v2/os/gcmd"
  8. "nodeMonitor/internal/consts"
  9. "nodeMonitor/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. // Custom enhance API document.
  22. enhanceOpenAPIDoc(s)
  23. s.Run()
  24. return nil
  25. },
  26. }
  27. )
  28. func enhanceOpenAPIDoc(s *ghttp.Server) {
  29. openapi := s.GetOpenApi()
  30. openapi.Config.CommonResponse = ghttp.DefaultHandlerResponse{}
  31. openapi.Config.CommonResponseDataField = `Data`
  32. // API description.
  33. openapi.Info = goai.Info{
  34. Title: consts.OpenAPITitle,
  35. Description: consts.OpenAPIDescription,
  36. Contact: &goai.Contact{
  37. Name: "GoFrame",
  38. URL: "https://goframe.org",
  39. },
  40. }
  41. }