123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package main
- import (
- "flag"
- "fmt"
- "log"
- "net/rpc"
- )
- type FcRequest struct {
- RedisFKey string
- InfoId string
- Id string
- Pname string
- Purchasing string
- Buyer string
- Area string
- City string
- Budget float64
- BuyerContent []string
- }
- type JyResponse struct {
- Rep []map[string]interface{}
- }
- type FcResponse struct {
- Rep bool
- }
- //附件
- type AtRequest struct {
- InfoId string
- }
- var id, pname, area, city, content string
- func main() {
- //
- //flag.StringVar(&id, "id", "", "项目id")
- //flag.StringVar(&pname, "pname", "", "项目名称")
- //flag.StringVar(&area, "area", "", "省份")
- //flag.StringVar(&city, "city", "", "城市")
- //flag.StringVar(&content, "content", "", "标的物,逗号隔开")
- //flag.Parse()
- //
- //if id != "" && pname != "" && content != "" {
- // conn, err := rpc.DialHTTP("tcp", "172.17.145.178:10082")
- // if err != nil {
- // log.Fatalln("dailing error: ", err)
- // }
- // req := &FcRequest{
- // RedisFKey: "forcast_res_" + id,
- // Id: id,
- // Pname: pname,
- // Area: area,
- // City: city,
- // BuyerContent: strings.Split(content, ","),
- // }
- // var res FcResponse
- // err = conn.Call("JyService.Forecast", req, &res)
- // if err != nil {
- // log.Fatalln("JyService error: ", err)
- // }
- // fmt.Println("-------", res)
- //}else {
- // flag.PrintDefaults()
- //}
- flag.StringVar(&id, "id", "5f4c5d6a7073b821a8d7f19e", "公告id")
- flag.Parse()
- if id != "" {
- conn, err := rpc.DialHTTP("tcp", "192.168.20.61:10082")
- if err != nil {
- log.Fatalln("dailing error: ", err)
- }
- req := AtRequest{
- InfoId: id,
- }
- var res JyResponse
- err = conn.Call("JyService.Download", req, &res)
- if err != nil {
- log.Fatalln("JyService error: ", err)
- }
- _ = conn.Close()
- fmt.Println("-------", req.InfoId, res.Rep)
- } else {
- flag.PrintDefaults()
- }
- }
- //服务地址配置
- //const (
- // rdserver = "192.168.3.240:10021"
- //
- // //TODO 目前实现前2中
- // ERROR_ERTRY_TYPE_FIRST = iota //1次,找到第一个服务提供者,出错即返回
- // ERROR_ERTRY_TYPE_FIRST_5 //5次尝试,找到第一个服务提供者
- // ERROR_ERTRY_TYPE_OVER_ALL //尝试遍历所有服务,直至又一个提供正常返回
- //)
- //
- //func main() {
- // conn, err := grpc.Dial(rdserver, grpc.WithInsecure())
- // if err != nil {
- // log.Println(err)
- // }
- // var client proto.ServiceClient
- // client = proto.NewServiceClient(conn)
- // repl, err := client.Apply(context.Background(), &proto.ApplyReqData{Name: "winner_predict", Balance: 0})
- // if err != nil {
- // log.Println(err)
- // }
- // log.Println("结果", repl.Ip, repl.Port)
- // //2.业务调用
- // addr := fmt.Sprintf("%s:%d", repl.Ip, repl.Port)
- // conn_b, err := grpc.Dial(addr, grpc.WithInsecure())
- // if err != nil {
- // log.Println(err)
- // }
- // defer conn_b.Close()
- // pc := proto.NewWinnerPredictServiceClient(conn_b)
- // rep, err := pc.Predict(context.Background(), &proto.PredictReq{
- // ProjectName: "北京拓普",
- // Mount: 3500000.01,
- // BidUnit: "河南中国",
- // Area: "河南",
- // City: "郑州",
- // Goods: []string{"笔记本1", "笔记本2"},
- // Winner: "经营部",
- // WinnerOrder: []string{"胜利1", "胜利2", "胜利3"},
- // })
- // log.Println(rep.Item)
- //}
|