36 lines
657 B
Go
36 lines
657 B
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/huoxue1/min-report/config"
|
||
|
"github.com/spf13/cobra"
|
||
|
"github.com/spf13/viper"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
rootCmd = cobra.Command{
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
if err := server().Run(fmt.Sprintf("%s:%d", viper.GetString("http.address"), viper.GetInt("http.port"))); err != nil {
|
||
|
return
|
||
|
}
|
||
|
},
|
||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||
|
config.InitConfig(configFile)
|
||
|
},
|
||
|
}
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
configFile string
|
||
|
)
|
||
|
|
||
|
func Run() {
|
||
|
if err := rootCmd.Execute(); err != nil {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "./config.yaml", "config file")
|
||
|
}
|