-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
50 lines (41 loc) · 868 Bytes
/
main.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
package main
import (
"api/core"
"api/people"
"context"
"log"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)
const (
address = "0.0.0.0:3002"
)
var (
data = map[string]string{
"foo": "bar",
}
)
type server struct{}
func (s *server) GetName(ctx context.Context, in *core.Info) (*people.Name, error) {
name := data[in.Name]
if name == "" {
name = "bar"
}
return &people.Name{Value: name}, nil
}
func main() {
lis, err := net.Listen("tcp", address)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
people.RegisterBioServer(s, &server{})
hs := health.NewServer()
hs.SetServingStatus("grpc.health.v1.bio", 1)
healthpb.RegisterHealthServer(s, hs)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}