resource.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package global
  2. import (
  3. "runtime"
  4. accgrpc "go-common/app/service/main/account/api"
  5. arcgrpc "go-common/app/service/main/archive/api"
  6. "go-common/app/service/main/up/conf"
  7. "go-common/library/database/sql"
  8. "go-common/library/sync/pipeline/fanout"
  9. "github.com/pkg/errors"
  10. )
  11. var (
  12. upCrmDB *sql.DB
  13. worker *fanout.Fanout
  14. arcCli arcgrpc.ArchiveClient
  15. accCli accgrpc.AccountClient
  16. )
  17. // GetArcClient .
  18. func GetArcClient() arcgrpc.ArchiveClient {
  19. return arcCli
  20. }
  21. // GetAccClient .
  22. func GetAccClient() accgrpc.AccountClient {
  23. return accCli
  24. }
  25. // GetWorker .
  26. func GetWorker() *fanout.Fanout {
  27. return worker
  28. }
  29. // GetUpCrmDB .
  30. func GetUpCrmDB() *sql.DB {
  31. return upCrmDB
  32. }
  33. //Init init global
  34. func Init(c *conf.Config) {
  35. var err error
  36. if arcCli, err = arcgrpc.NewClient(c.GRPCClient.Archive); err != nil {
  37. panic(errors.WithMessage(err, "Failed to dial archive service"))
  38. }
  39. if accCli, err = accgrpc.NewClient(c.GRPCClient.Account); err != nil {
  40. panic(errors.WithMessage(err, "Failed to dial account service"))
  41. }
  42. upCrmDB = sql.NewMySQL(c.DB.UpCRM)
  43. worker = fanout.New("cache", fanout.Worker(runtime.NumCPU()), fanout.Buffer(1024))
  44. }
  45. // Close .
  46. func Close() {
  47. upCrmDB.Close()
  48. worker.Close()
  49. }