client.go 3.1 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", "", "公告id")
  63. flag.Parse()
  64. if id != "" {
  65. conn, err := rpc.DialHTTP("tcp", "192.168.3.128: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. fmt.Println("-------", req.InfoId, res.Rep)
  78. }else {
  79. flag.PrintDefaults()
  80. }
  81. }
  82. //服务地址配置
  83. //const (
  84. // rdserver = "192.168.3.240:10021"
  85. //
  86. // //TODO 目前实现前2中
  87. // ERROR_ERTRY_TYPE_FIRST = iota //1次,找到第一个服务提供者,出错即返回
  88. // ERROR_ERTRY_TYPE_FIRST_5 //5次尝试,找到第一个服务提供者
  89. // ERROR_ERTRY_TYPE_OVER_ALL //尝试遍历所有服务,直至又一个提供正常返回
  90. //)
  91. //
  92. //func main() {
  93. // conn, err := grpc.Dial(rdserver, grpc.WithInsecure())
  94. // if err != nil {
  95. // log.Println(err)
  96. // }
  97. // var client proto.ServiceClient
  98. // client = proto.NewServiceClient(conn)
  99. // repl, err := client.Apply(context.Background(), &proto.ApplyReqData{Name: "winner_predict", Balance: 0})
  100. // if err != nil {
  101. // log.Println(err)
  102. // }
  103. // log.Println("结果", repl.Ip, repl.Port)
  104. // //2.业务调用
  105. // addr := fmt.Sprintf("%s:%d", repl.Ip, repl.Port)
  106. // conn_b, err := grpc.Dial(addr, grpc.WithInsecure())
  107. // if err != nil {
  108. // log.Println(err)
  109. // }
  110. // defer conn_b.Close()
  111. // pc := proto.NewWinnerPredictServiceClient(conn_b)
  112. // rep, err := pc.Predict(context.Background(), &proto.PredictReq{
  113. // ProjectName: "北京拓普",
  114. // Mount: 3500000.01,
  115. // BidUnit: "河南中国",
  116. // Area: "河南",
  117. // City: "郑州",
  118. // Goods: []string{"笔记本1", "笔记本2"},
  119. // Winner: "经营部",
  120. // WinnerOrder: []string{"胜利1", "胜利2", "胜利3"},
  121. // })
  122. // log.Println(rep.Item)
  123. //}