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", "", "公告id") flag.Parse() if id != "" { conn, err := rpc.DialHTTP("tcp", "192.168.3.128: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) } 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) //}