Last active
October 30, 2018 13:08
-
-
Save tj/f6b4dc43396a51a3f1a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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