42 lines
741 B
Go
42 lines
741 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
"gitter.top/common/lormatter"
|
|
|
|
"pastebin/config"
|
|
)
|
|
|
|
var (
|
|
rootCmd = &cobra.Command{}
|
|
cfgFile string
|
|
)
|
|
|
|
func Execute() {
|
|
// 预加载配置文件
|
|
loadConfig()
|
|
if err := rootCmd.Execute(); err != nil {
|
|
logrus.Fatalf("exec command failed: %v", err)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
var formatter = lormatter.Formatter{
|
|
ShowTime: true,
|
|
ShowFile: true,
|
|
}
|
|
formatter.Register()
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "config_dev.yaml", "config file")
|
|
rootCmd.AddCommand(apiServerCommand) // API服务
|
|
}
|
|
|
|
func loadConfig() {
|
|
// 初始化配置文件
|
|
config.New(cfgFile)
|
|
conf := config.Get()
|
|
if err := conf.Load(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|