main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "Cold_Logistic/internal/pkg/common/global"
  4. "Cold_Logistic/internal/pkg/common/options"
  5. "Cold_Logistic/internal/server/adapter"
  6. "fmt"
  7. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/app"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core/middleware"
  9. "math/rand"
  10. "runtime"
  11. "time"
  12. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/app/server"
  13. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/app/toolkit"
  14. )
  15. func init() {
  16. rand.Seed(time.Now().UTC().UnixNano())
  17. runtime.GOMAXPROCS(runtime.NumCPU())
  18. }
  19. // nohup ./Cold_Logistic run --profile=../configs/test.yaml &
  20. func main() {
  21. opt := options.NewOptions()
  22. s := server.NewServer(
  23. server.WithCustomConfigStructPtr(opt),
  24. server.WithOnConfigFileChange(opt),
  25. server.WithHttpServer(
  26. server.WithGlobalMiddleware(
  27. middleware.AddRequestID(),
  28. middleware.Limit(10000, 5*1000),
  29. ),
  30. server.WithDefaultHealthApi(),
  31. server.WithDefaultVersionApi(),
  32. server.WithDefaultMetricApi(""),
  33. server.WithDefaultPprofApi(""),
  34. server.WithHTTPApi(adapter.HttpRoutes()),
  35. ),
  36. server.WithCronJob(server.WithCronApi(adapter.RegisterCron())),
  37. server.WithSelfMonitor(),
  38. server.WithComponent(global.NewCommonConnectsRepo(opt)),
  39. )
  40. a := app.NewApp("server")
  41. a.AddCommand(
  42. s.NewRunCommand(),
  43. toolkit.NewVersionCommand(a.GetFileName()),
  44. )
  45. if err := a.Run(); err != nil {
  46. panic(fmt.Sprintf("Error:%v\n", err))
  47. }
  48. }