main.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. "github.com/joho/godotenv"
  10. "golang.org/x/sync/errgroup"
  11. )
  12. var (
  13. // default build fields populated by GoReleaser
  14. version = "dev"
  15. commit = "none"
  16. date = "unknown"
  17. )
  18. func init() {
  19. cfgFile := flag.String("config", "settings.env", "Path to config file")
  20. showHelp := flag.Bool("help", false, "Display help")
  21. showVersion := flag.Bool("version", false, "Display build information")
  22. flag.Parse()
  23. switch {
  24. case *showVersion:
  25. fmt.Printf("%-10s %s\n", "version:", version)
  26. fmt.Printf("%-10s %s\n", "commit:", commit)
  27. fmt.Printf("%-10s %s\n", "date:", date)
  28. os.Exit(0)
  29. case *showHelp:
  30. flag.PrintDefaults()
  31. os.Exit(0)
  32. }
  33. // optionally populate environment variables with config file
  34. if err := godotenv.Load(*cfgFile); err != nil {
  35. fmt.Printf("Config file (%s) not found, defaulting to env vars for app config...\n", *cfgFile)
  36. } else {
  37. fmt.Printf("Successfully loaded config file (%s)\n", *cfgFile)
  38. }
  39. }
  40. func main() {
  41. ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
  42. defer stop()
  43. type starter interface {
  44. Start(ctx context.Context) error
  45. }
  46. var g errgroup.Group
  47. start := func(fn starter) {
  48. g.Go(func() error { return fn.Start(ctx) })
  49. }
  50. deps, err := MakeCommonDeps()
  51. if err != nil {
  52. fmt.Printf("error initializing common deps: %v\n", err)
  53. os.Exit(1)
  54. }
  55. start(Admin(deps))
  56. start(Alert(deps))
  57. start(Auth(deps))
  58. start(BART(deps))
  59. start(BOS(deps))
  60. start(Chat(deps))
  61. start(ChatNav(deps))
  62. start(MgmtAPI(deps))
  63. start(ODir(deps))
  64. start(TOC(deps))
  65. if err := g.Wait(); err != nil {
  66. fmt.Println(err.Error())
  67. os.Exit(1)
  68. }
  69. }