This repository has been archived on 2022-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
lrpc/examples/client/main.go

39 lines
626 B
Go
Raw Normal View History

2022-05-01 08:39:22 +00:00
package main
import (
"context"
2022-05-01 08:39:22 +00:00
"encoding/gob"
"fmt"
"net"
"go.arsenm.dev/lrpc/client"
"go.arsenm.dev/lrpc/codec"
)
func main() {
gob.Register([2]int{})
ctx := context.Background()
2022-05-01 08:39:22 +00:00
conn, _ := net.Dial("tcp", "localhost:9090")
c := client.New(conn, codec.Gob)
defer c.Close()
var add int
c.Call(ctx, "Arith", "Add", [2]int{5, 5}, &add)
2022-05-01 08:39:22 +00:00
var sub int
c.Call(ctx, "Arith", "Sub", [2]int{5, 5}, &sub)
2022-05-01 08:39:22 +00:00
var mul int
c.Call(ctx, "Arith", "Mul", [2]int{5, 5}, &mul)
2022-05-01 08:39:22 +00:00
var div int
c.Call(ctx, "Arith", "Div", [2]int{5, 5}, &div)
2022-05-01 08:39:22 +00:00
fmt.Printf(
"add: %d, sub: %d, mul: %d, div: %d\n",
add, sub, mul, div,
)
}