func (this *ArithDivide) Divide(args *entity.ArithRequest, reply *entity.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 }
func main() { stub, client, err := server.DialArithServiceMultiply("tcp", "192.168.2.172:62228") //stub, client, err := server.DialArithServiceDivide("tcp", "192.168.2.172:62228") if err != nil { log.Fatal(`arith.DialArithService("tcp", "192.168.2.172:62228"`, err) } defer client.Close() var args entity.ArithRequest var reply entity.ArithResponse args.A = proto.Int32(7) args.B = proto.Int32(2) 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()) }
func (this *ArithMutiply) Multiply(args *entity.ArithRequest, reply *entity.ArithResponse) error { reply.Val = proto.Int32(args.GetA() * args.GetB()) return nil }