http.go 725 B

123456789101112131415161718192021222324252627282930313233
  1. package cmd
  2. import (
  3. "fmt"
  4. "kpt-tmr-group/config"
  5. "kpt-tmr-group/dep"
  6. "kpt-tmr-group/http"
  7. "kpt-tmr-group/pkg/logger/logrus"
  8. "github.com/spf13/cobra"
  9. )
  10. // httpCmd represents the http command
  11. var httpCmd = &cobra.Command{
  12. Use: "http",
  13. Short: "start http server",
  14. Run: func(cmd *cobra.Command, args []string) {
  15. bootHTTPServer(config.Options())
  16. },
  17. }
  18. func bootHTTPServer(cfg *config.AppConfig) {
  19. dependency := dep.DIHttpDependency()
  20. logrus.Info("kpt-tmr-group: boot HTTP server")
  21. server := http.NewServer(
  22. http.ExportLogOption(),
  23. http.WithDependency(dependency),
  24. http.SetRouteOption(),
  25. )
  26. if err := server.Run(cfg.HTTPServerAddr); err != nil {
  27. fmt.Printf("HTTPServer run failed, err: %s", err)
  28. }
  29. }