Beispiel #1
0
func (t *Arith) Divide(args *arith.ArithRequest, reply *arith.ArithResponse) error {
	if args.GetB() == 0 {
		return errors.New("divide by zero")
	}
	reply.Quo = proto.Int32(args.GetA() / args.GetB())
	reply.Rem = proto.Int32(args.GetA() % args.GetB())
	return nil
}
Beispiel #2
0
func main() {

	stub, client, err := arith.DialArithService("tcp", "192.168.2.172:62222")
	if err != nil {
		log.Fatal(`arith.DialArithService("tcp", "192.168.2.172:62222"`, err)
	}
	defer client.Close()

	var args arith.ArithRequest
	var reply arith.ArithResponse

	args.A = proto.Int32(7)
	args.B = proto.Int32(8)

	if err = stub.Multiply(&args, &reply); err != nil {
		log.Fatal("arith error:", err)
	}
	fmt.Printf("Arith: %d*%d=%d\n", args.GetA(), args.GetB(), reply.GetVal())
}
Beispiel #3
0
func (t *Arith) Multiply(args *arith.ArithRequest, reply *arith.ArithResponse) error {
	reply.Val = proto.Int32(args.GetA() * args.GetB())
	return nil
}