client.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "net/rpc"
  7. )
  8. type FcRequest struct {
  9. RedisFKey string
  10. InfoId string
  11. Id string
  12. Pname string
  13. Purchasing string
  14. Buyer string
  15. Area string
  16. City string
  17. Budget float64
  18. BuyerContent []string
  19. }
  20. type JyResponse struct {
  21. Rep []map[string]interface{}
  22. }
  23. type FcResponse struct {
  24. Rep bool
  25. }
  26. //附件
  27. type AtRequest struct {
  28. InfoId string
  29. }
  30. var id, pname, area, city, content string
  31. func main() {
  32. //
  33. //flag.StringVar(&id, "id", "", "项目id")
  34. //flag.StringVar(&pname, "pname", "", "项目名称")
  35. //flag.StringVar(&area, "area", "", "省份")
  36. //flag.StringVar(&city, "city", "", "城市")
  37. //flag.StringVar(&content, "content", "", "标的物,逗号隔开")
  38. //flag.Parse()
  39. //
  40. //if id != "" && pname != "" && content != "" {
  41. // conn, err := rpc.DialHTTP("tcp", "172.17.145.178:10082")
  42. // if err != nil {
  43. // log.Fatalln("dailing error: ", err)
  44. // }
  45. // req := &FcRequest{
  46. // RedisFKey: "forcast_res_" + id,
  47. // Id: id,
  48. // Pname: pname,
  49. // Area: area,
  50. // City: city,
  51. // BuyerContent: strings.Split(content, ","),
  52. // }
  53. // var res FcResponse
  54. // err = conn.Call("JyService.Forecast", req, &res)
  55. // if err != nil {
  56. // log.Fatalln("JyService error: ", err)
  57. // }
  58. // fmt.Println("-------", res)
  59. //}else {
  60. // flag.PrintDefaults()
  61. //}
  62. flag.StringVar(&id, "id", "5f4c5d6a7073b821a8d7f19e", "公告id")
  63. flag.Parse()
  64. if id != "" {
  65. conn, err := rpc.DialHTTP("tcp", "192.168.20.61:10082")
  66. if err != nil {
  67. log.Fatalln("dailing error: ", err)
  68. }
  69. req := AtRequest{
  70. InfoId: id,
  71. }
  72. var res JyResponse
  73. err = conn.Call("JyService.Download", req, &res)
  74. if err != nil {
  75. log.Fatalln("JyService error: ", err)
  76. }
  77. _ = conn.Close()
  78. fmt.Println("-------", req.InfoId, res.Rep)
  79. } else {
  80. flag.PrintDefaults()
  81. }
  82. }
  83. //服务地址配置
  84. //const (
  85. // rdserver = "192.168.3.240:10021"
  86. //
  87. // //TODO 目前实现前2中
  88. // ERROR_ERTRY_TYPE_FIRST = iota //1次,找到第一个服务提供者,出错即返回
  89. // ERROR_ERTRY_TYPE_FIRST_5 //5次尝试,找到第一个服务提供者
  90. // ERROR_ERTRY_TYPE_OVER_ALL //尝试遍历所有服务,直至又一个提供正常返回
  91. //)
  92. //
  93. //func main() {
  94. // conn, err := grpc.Dial(rdserver, grpc.WithInsecure())
  95. // if err != nil {
  96. // log.Println(err)
  97. // }
  98. // var client proto.ServiceClient
  99. // client = proto.NewServiceClient(conn)
  100. // repl, err := client.Apply(context.Background(), &proto.ApplyReqData{Name: "winner_predict", Balance: 0})
  101. // if err != nil {
  102. // log.Println(err)
  103. // }
  104. // log.Println("结果", repl.Ip, repl.Port)
  105. // //2.业务调用
  106. // addr := fmt.Sprintf("%s:%d", repl.Ip, repl.Port)
  107. // conn_b, err := grpc.Dial(addr, grpc.WithInsecure())
  108. // if err != nil {
  109. // log.Println(err)
  110. // }
  111. // defer conn_b.Close()
  112. // pc := proto.NewWinnerPredictServiceClient(conn_b)
  113. // rep, err := pc.Predict(context.Background(), &proto.PredictReq{
  114. // ProjectName: "北京拓普",
  115. // Mount: 3500000.01,
  116. // BidUnit: "河南中国",
  117. // Area: "河南",
  118. // City: "郑州",
  119. // Goods: []string{"笔记本1", "笔记本2"},
  120. // Winner: "经营部",
  121. // WinnerOrder: []string{"胜利1", "胜利2", "胜利3"},
  122. // })
  123. // log.Println(rep.Item)
  124. //}