-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
39 lines (30 loc) · 911 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"net"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
pb "github.com/ppg/grpc-intro/proto"
)
// START SERVICE IMPLEMENTATION OMIT
type testService struct {
}
func (s *testService) Add(ctx context.Context, req *pb.NumericRequest) (*pb.NumericResponse, error) {
grpclog.Printf("v1=%d, v2=%d", req.V1, req.V2)
return &pb.NumericResponse{R: req.V1 + req.V2}, nil
}
// END SERVICE IMPLEMENTATION OMIT
func main() {
listener, err := net.Listen("tcp", ":1234")
if err != nil {
grpclog.Fatalf("failed to listen: %v", err)
}
// Create a gRPC server and attach our service to it
server := grpc.NewServer()
pb.RegisterTestServer(server, &testService{})
// Start handling requests
grpclog.Printf("Starting to listen on %s", listener.Addr())
if err = server.Serve(listener); err != nil {
grpclog.Fatalf("failed to serve: %v", err)
}
}