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/server/main.go

39 lines
624 B
Go
Raw Normal View History

2022-05-01 08:39:22 +00:00
package main
import (
2022-05-13 00:13:44 +00:00
"context"
2022-05-01 08:39:22 +00:00
"encoding/gob"
"net"
"go.arsenm.dev/lrpc/codec"
"go.arsenm.dev/lrpc/server"
)
type Arith struct{}
func (Arith) Add(ctx *server.Context, in [2]int) int {
return in[0] + in[1]
}
func (Arith) Mul(ctx *server.Context, in [2]int) int {
return in[0] * in[1]
}
func (Arith) Div(ctx *server.Context, in [2]int) int {
return in[0] / in[1]
}
func (Arith) Sub(ctx *server.Context, in [2]int) int {
return in[0] - in[1]
}
func main() {
gob.Register([2]int{})
s := server.New()
s.Register(Arith{})
ln, _ := net.Listen("tcp", ":9090")
2022-05-13 00:13:44 +00:00
s.Serve(context.Background(), ln, codec.Gob)
2022-05-01 08:39:22 +00:00
}