http.go 722 B

12345678910111213141516171819202122232425262728293031323334
  1. package cmd
  2. import (
  3. "fmt"
  4. "kpt-event/config"
  5. "kpt-event/dep"
  6. "kpt-event/http"
  7. log "gitee.com/xuyiping_admin/pkg/logger/zaplog"
  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. log.Info("kpt-event: 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. }