蛋蛋星球RabbitMq消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpc_client.go 1.4 KiB

4 viikkoa sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package utils
  2. import (
  3. "applet/pkg/pb"
  4. "context"
  5. "fmt"
  6. "google.golang.org/grpc"
  7. "google.golang.org/grpc/metadata"
  8. "strconv"
  9. "time"
  10. )
  11. func GetBusinessIntClient(url, port string) pb.BusinessIntClient {
  12. target := fmt.Sprintf("%s:%s", url, port)
  13. conn, err := grpc.Dial(target, grpc.WithInsecure())
  14. if err != nil {
  15. fmt.Println(err)
  16. return nil
  17. }
  18. return pb.NewBusinessIntClient(conn)
  19. }
  20. func GetBusinessExtClient(url, port string) pb.BusinessExtClient {
  21. target := fmt.Sprintf("%s:%s", url, port)
  22. conn, err := grpc.Dial(target, grpc.WithInsecure())
  23. //defer conn.Close()
  24. if err != nil {
  25. fmt.Println(err)
  26. return nil
  27. }
  28. return pb.NewBusinessExtClient(conn)
  29. }
  30. func GetLogicExtClient(url, port string) pb.LogicExtClient {
  31. target := fmt.Sprintf("%s:%s", url, port)
  32. conn, err := grpc.Dial(target, grpc.WithInsecure())
  33. if err != nil {
  34. fmt.Println(err)
  35. return nil
  36. }
  37. return pb.NewLogicExtClient(conn)
  38. }
  39. func GetCtx(token, userId, deviceId, masterId string) context.Context {
  40. if userId == "" {
  41. userId = "1"
  42. }
  43. if deviceId == "" {
  44. deviceId = "1"
  45. }
  46. if token == "" {
  47. token = "0"
  48. }
  49. return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
  50. "user_id", userId,
  51. "device_id", deviceId,
  52. "token", token,
  53. "master_id", masterId,
  54. "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
  55. }
  56. func UnixMilliTime(t time.Time) int64 {
  57. return t.UnixNano() / 1000000
  58. }