本文整理汇总了Golang中github.com/cockroachdb/cockroach/rpc/codec/message.ArithRequest类的典型用法代码示例。如果您正苦于以下问题:Golang ArithRequest类的具体用法?Golang ArithRequest怎么用?Golang ArithRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArithRequest类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Div
func (t *Arith) Div(args *message.ArithRequest, reply *message.ArithResponse) error {
if args.GetB() == 0 {
return errors.New("divide by zero")
}
reply.C = args.GetA() / args.GetB()
return nil
}
示例2: Add
func (t *Arith) Add(args *message.ArithRequest, reply *message.ArithResponse) error {
reply.C = args.GetA() + args.GetB()
log.Infof("Arith.Add(%v, %v): %v", args.GetA(), args.GetB(), reply.GetC())
return nil
}
示例3: Mul
func (t *Arith) Mul(args *message.ArithRequest, reply *message.ArithResponse) error {
reply.C = args.GetA() * args.GetB()
return nil
}
示例4: testArithClient
func testArithClient(t *testing.T, client *rpc.Client) {
var args message.ArithRequest
var reply message.ArithResponse
var err error
// Add
args.A = 1
args.B = 2
if err = client.Call("ArithService.Add", &args, &reply); err != nil {
t.Fatalf(`arith.Add: %v`, err)
}
if reply.GetC() != 3 {
t.Fatalf(`arith.Add: expected = %d, got = %d`, 3, reply.GetC())
}
// Mul
args.A = 2
args.B = 3
if err = client.Call("ArithService.Mul", &args, &reply); err != nil {
t.Fatalf(`arith.Mul: %v`, err)
}
if reply.GetC() != 6 {
t.Fatalf(`arith.Mul: expected = %d, got = %d`, 6, reply.GetC())
}
// Div
args.A = 13
args.B = 5
if err = client.Call("ArithService.Div", &args, &reply); err != nil {
t.Fatalf(`arith.Div: %v`, err)
}
if reply.GetC() != 2 {
t.Fatalf(`arith.Div: expected = %d, got = %d`, 2, reply.GetC())
}
// Div zero
args.A = 1
args.B = 0
if err = client.Call("ArithService.Div", &args, &reply); err.Error() != "divide by zero" {
t.Fatalf(`arith.Error: expected = "%s", got = "%s"`, "divide by zero", err.Error())
}
// Error
args.A = 1
args.B = 2
if err = client.Call("ArithService.Error", &args, &reply); err.Error() != "ArithError" {
t.Fatalf(`arith.Error: expected = "%s", got = "%s"`, "ArithError", err.Error())
}
}