main.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "context"
  4. "github.com/vladimirok5959/golang-ctrlc/ctrlc"
  5. "github.com/vladimirok5959/golang-ip2location/internal/client"
  6. "github.com/vladimirok5959/golang-ip2location/internal/consts"
  7. "github.com/vladimirok5959/golang-ip2location/internal/server"
  8. "github.com/vladimirok5959/golang-ip2location/internal/workers/worker_reloader"
  9. "github.com/vladimirok5959/golang-utils/utils/http/logger"
  10. "github.com/vladimirok5959/golang-utils/utils/penv"
  11. )
  12. func init() {
  13. if err := penv.ProcessConfig(&consts.Config); err != nil {
  14. panic(err)
  15. }
  16. var err error
  17. if consts.Config.DataDir == "" {
  18. consts.Config.DataDir, err = consts.DataPath()
  19. if err != nil {
  20. panic(err)
  21. }
  22. }
  23. }
  24. func main() {
  25. logger.AccessLogFile = consts.Config.AccessLogFile
  26. logger.ErrorLogFile = consts.Config.ErrorLogFile
  27. ctrlc.App(func(ctx context.Context, shutdown context.CancelFunc) *[]ctrlc.Iface {
  28. cl, err := client.New(ctx, shutdown)
  29. if err != nil {
  30. return ctrlc.MakeError(shutdown, ctrlc.AppError(err))
  31. }
  32. sv, err := server.New(ctx, shutdown, cl)
  33. if err != nil {
  34. return ctrlc.MakeError(shutdown, ctrlc.AppError(err), cl)
  35. }
  36. workerReloader := worker_reloader.New(cl)
  37. return &[]ctrlc.Iface{
  38. workerReloader,
  39. sv,
  40. cl,
  41. }
  42. })
  43. }