-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
65 lines (47 loc) · 1.1 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"net"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"github.com/grpc/add/calc"
)
type server struct {}
type Hello struct {
a int32
}
func main() {
lis, err := net.Listen("tcp", ":9090")
if err != nil {
panic(err)
}
var result []Hello
result = append(result, Hello{
a: 32,
})
fmt.Printf("Result %v", result)
fmt.Println("Server running")
srv := grpc.NewServer()
calc.RegisterAddServiceServer(srv, &server{})
reflection.Register(srv)
if e := srv.Serve(lis); e !=nil {
panic(e)
}
fmt.Println("Server running")
}
var result calc.Response;
func (s *server) Add(ctx context.Context, request *calc.Request)(*calc.Response, error) {
name, email, phone := request.GetName(), request.GetEmail(), request.GetPhone()
fmt.Println("Data from clinet %v, %v, %v", name, email, phone)
obj := &calc.Request{
Name: name,
Email: email,
Phone: phone,
}
result.Result = append(result.Result, obj)
return &result, nil
}
func (s *server) GetAll(ctx context.Context, request *calc.Request)(*calc.Response, error) {
return &result, nil
}