resource.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package global
  2. import (
  3. "go-common/app/interface/main/mcn/conf"
  4. taggrpc "go-common/app/interface/main/tag/api"
  5. accgrpc "go-common/app/service/main/account/api"
  6. arcgrpc "go-common/app/service/main/archive/api"
  7. memgrpc "go-common/app/service/main/member/api"
  8. "go-common/library/cache/memcache"
  9. bm "go-common/library/net/http/blademaster"
  10. "github.com/pkg/errors"
  11. )
  12. var (
  13. accGRPC accgrpc.AccountClient
  14. memGRPC memgrpc.MemberClient
  15. arcGRPC arcgrpc.ArchiveClient
  16. tagGRPC taggrpc.TagRPCClient
  17. mc *memcache.Pool
  18. bmClient *bm.Client
  19. )
  20. // GetAccGRPC .
  21. func GetAccGRPC() accgrpc.AccountClient {
  22. return accGRPC
  23. }
  24. // GetMemGRPC .
  25. func GetMemGRPC() memgrpc.MemberClient {
  26. return memGRPC
  27. }
  28. // GetArcGRPC .
  29. func GetArcGRPC() arcgrpc.ArchiveClient {
  30. return arcGRPC
  31. }
  32. // GetTagGRPC .
  33. func GetTagGRPC() taggrpc.TagRPCClient {
  34. return tagGRPC
  35. }
  36. // GetMc get mc
  37. func GetMc() *memcache.Pool {
  38. return mc
  39. }
  40. // GetBMClient get http client
  41. func GetBMClient() *bm.Client {
  42. return bmClient
  43. }
  44. //Init init global
  45. func Init(c *conf.Config) {
  46. var err error
  47. if accGRPC, err = accgrpc.NewClient(c.GRPCClient.Account); err != nil {
  48. panic(errors.WithMessage(err, "Failed to dial account service"))
  49. }
  50. if memGRPC, err = memgrpc.NewClient(c.GRPCClient.Member); err != nil {
  51. panic(errors.WithMessage(err, "Failed to dial member service"))
  52. }
  53. if arcGRPC, err = arcgrpc.NewClient(c.GRPCClient.Archive); err != nil {
  54. panic(errors.WithMessage(err, "Failed to dial archive service"))
  55. }
  56. if tagGRPC, err = taggrpc.NewClient(c.GRPCClient.Tag); err != nil {
  57. panic(errors.WithMessage(err, "Failed to dial tag service"))
  58. }
  59. mc = memcache.NewPool(&c.Memcache.Config)
  60. bmClient = bm.NewClient(c.HTTPClient)
  61. }