'Arguments of go rpc. When should they be pointer?
I have read go rpc documentation, and find out one of the 4 criteria:
the method's second argument is a pointer.
The method below shows the right way to use go rpc, thus the second parameter is a pointer *T2.
func (t *T) MethodName(argType T1, replyType *T2) error
Is there any reason for this criteria? Why should it be a pointer?
After I read more examples, find that for most of time, even the first argument is a pointer!
func (t *Arith) Multiply(args *Args, reply *int) error {
*reply = args.A * args.B
return nil
}
I know the difference between pointer type and common type, but I'm not sure about it in rpc context.
Solution 1:[1]
Reply must be a pointer so the function can assign a value to it.
It is similar to the example here: https://gobyexample.com/pointers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lars Christian Jensen |
