package cmd

import (
	"fmt"
	"kpt-pasture/config"
	"kpt-pasture/dep"
	"kpt-pasture/http"

	"gitee.com/xuyiping_admin/pkg/logger/logrus"

	"github.com/spf13/cobra"
)

// httpCmd represents the http command
var httpCmd = &cobra.Command{
	Use:   "http",
	Short: "start http server",
	Run: func(cmd *cobra.Command, args []string) {
		bootHTTPServer(config.Options())
	},
}

func bootHTTPServer(cfg *config.AppConfig) {
	dependency := dep.DIHttpDependency()
	logrus.Info("kpt-pasture: boot HTTP server")
	server := http.NewServer(
		http.ExportLogOption(),
		http.WithDependency(dependency),
		http.SetRouteOption(),
	)
	if err := server.Run(cfg.HTTPServerAddr); err != nil {
		fmt.Printf("HTTPServer run failed, err: %s", err)
	}
}