本文整理匯總了Golang中github.com/cockroachdb/cockroach/rpc/codec/message.ArithResponse類的典型用法代碼示例。如果您正苦於以下問題:Golang ArithResponse類的具體用法?Golang ArithResponse怎麽用?Golang ArithResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ArithResponse類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: Mul
func (t *Arith) Mul(args *message.ArithRequest, reply *message.ArithResponse) error {
reply.C = args.GetA() * args.GetB()
return nil
}
示例3: 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
}
示例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())
}
}
示例5: Mul
func (t *Arith) Mul(args *message.ArithRequest, reply *message.ArithResponse) error {
reply.C = args.A * args.B
return nil
}
示例6: Add
func (t *Arith) Add(args *message.ArithRequest, reply *message.ArithResponse) error {
reply.C = args.A + args.B
log.Infof("Arith.Add(%v, %v): %v", args.A, args.B, reply.C)
return nil
}