蛋蛋星球-客户端
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.
 
 
 
 
 
 

60 lines
1.3 KiB

  1. package utils
  2. import (
  3. "applet/app/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 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. "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
  54. }