first commit
This commit is contained in:
21
cmd/api.go
Normal file
21
cmd/api.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"pastebin/register"
|
||||
)
|
||||
|
||||
var (
|
||||
apiServerCommand = &cobra.Command{
|
||||
Use: "api",
|
||||
Short: "start api server",
|
||||
Long: "start api server",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
router := register.NewRouter()
|
||||
if err := router.Register(); err != nil {
|
||||
logrus.Errorf("register router failed: %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
41
cmd/exec.go
Normal file
41
cmd/exec.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user