12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package neo
- import (
- "fmt"
- "log"
- "os"
- "os/signal"
- "github.com/go-admin-team/go-admin-core/config/source/file"
- "github.com/go-admin-team/go-admin-core/sdk/config"
- "github.com/go-admin-team/go-admin-core/sdk/pkg"
- "github.com/spf13/cobra"
- "go-admin/common/database"
- extConfig "go-admin/config"
- "go-admin/handler"
- "go-admin/handler/neo"
- )
- var (
- configYml string
- apiCheck bool
- StartCmd = &cobra.Command{
- Use: "neo",
- Short: "Start neo server",
- Example: "go-admin neo -c config/settings.yml",
- SilenceUsage: true,
- PreRun: func(cmd *cobra.Command, args []string) {
- setup()
- },
- RunE: func(cmd *cobra.Command, args []string) error {
- return run()
- },
- }
- )
- func init() {
- StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
- }
- func setup() {
- config.ExtendConfig = &extConfig.ExtConfig
- //1. 读取配置
- config.Setup(
- file.NewSource(file.WithPath(configYml)),
- database.Setup,
- // storage.Setup,
- // olap.Setup,
- )
- usageStr := `starting alert server...`
- log.Println(usageStr)
- }
- func run() error {
- go func() {
- neo.Run()
- }()
- defer handler.CloseAlertManager()
- fmt.Println(pkg.Red("Start neo Service"))
- quit := make(chan os.Signal, 1)
- signal.Notify(quit, os.Interrupt)
- <-quit
- // ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
- // defer cancel()
- fmt.Printf("%s Shutdown neo server ... \r\n", pkg.GetCurrentTimeStr())
- log.Println("Neo server exiting")
- return nil
- }
|