server.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package neo
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "os/signal"
  7. "github.com/go-admin-team/go-admin-core/config/source/file"
  8. "github.com/go-admin-team/go-admin-core/sdk/config"
  9. "github.com/go-admin-team/go-admin-core/sdk/pkg"
  10. "github.com/spf13/cobra"
  11. "go-admin/common/database"
  12. extConfig "go-admin/config"
  13. "go-admin/handler"
  14. "go-admin/handler/neo"
  15. )
  16. var (
  17. configYml string
  18. apiCheck bool
  19. StartCmd = &cobra.Command{
  20. Use: "neo",
  21. Short: "Start neo server",
  22. Example: "go-admin neo -c config/settings.yml",
  23. SilenceUsage: true,
  24. PreRun: func(cmd *cobra.Command, args []string) {
  25. setup()
  26. },
  27. RunE: func(cmd *cobra.Command, args []string) error {
  28. return run()
  29. },
  30. }
  31. )
  32. func init() {
  33. StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
  34. }
  35. func setup() {
  36. config.ExtendConfig = &extConfig.ExtConfig
  37. //1. 读取配置
  38. config.Setup(
  39. file.NewSource(file.WithPath(configYml)),
  40. database.Setup,
  41. // storage.Setup,
  42. // olap.Setup,
  43. )
  44. usageStr := `starting alert server...`
  45. log.Println(usageStr)
  46. }
  47. func run() error {
  48. go func() {
  49. neo.Run()
  50. }()
  51. defer handler.CloseAlertManager()
  52. fmt.Println(pkg.Red("Start neo Service"))
  53. quit := make(chan os.Signal)
  54. signal.Notify(quit, os.Interrupt)
  55. <-quit
  56. // ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
  57. // defer cancel()
  58. fmt.Printf("%s Shutdown neo server ... \r\n", pkg.GetCurrentTimeStr())
  59. log.Println("Neo server exiting")
  60. return nil
  61. }