Skip to content

Instantly share code, notes, and snippets.

@tj
Last active October 30, 2018 13:08
Show Gist options
  • Save tj/f6b4dc43396a51a3f1a8 to your computer and use it in GitHub Desktop.
Save tj/f6b4dc43396a51a3f1a8 to your computer and use it in GitHub Desktop.
package main
import "github.com/segmentio/rpc"
import "fmt"
type Args struct {
A int
B int
}
func main() {
client, _ := rpc.Dial("tcp", ":5000")
res := new(int)
client.Call("Add", &Args{5, 5}, res)
fmt.Printf("%d\n", *res)
}
package main
import "github.com/segmentio/rpc"
type Math struct{}
type Args struct {
A int
B int
}
func (m *Math) Add(req *Args, res *int) error {
*res = req.A + req.B
return nil
}
func (m *Math) Sub(req *Args, res *int) error {
*res = req.A - req.B
return nil
}
func main() {
math := new(Math)
rpc.New(math).ListenAndServe("tcp", ":5000")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment