-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (44 loc) · 1.32 KB
/
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 (
"cloud.google.com/go/profiler"
"flag"
"github.com/billcchung/example-service/ping"
pb "github.com/billcchung/example-service/proto"
"google.golang.org/grpc"
"log"
"net"
)
func main() {
var projectID string
var service string
var serviceVersion string
var address string
flag.StringVar(&projectID, "p", "", "The GCP Project ID")
flag.StringVar(&service, "s", "example-service", "The service name")
flag.StringVar(&serviceVersion, "v", "1", "The service version")
flag.StringVar(&address, "a", ":8080", "The address to listen for connections")
flag.Parse()
err := profiler.Start(profiler.Config{
Service: service,
ServiceVersion: serviceVersion,
ProjectID: projectID,
})
if err != nil {
log.Fatalf("Unable to start GCP profiler, err: %s", err)
}
log.Println("configured cloud profiler")
s := grpc.NewServer()
pb.RegisterPingServer(s, Ping.Server{})
if err != nil {
log.Fatalf("Failed to get new gRPC server, err: %s", err)
return
}
lis, err := net.Listen("tcp", address)
if err != nil {
log.Fatalf("Failed to listen for address '%s', err: %s", address, err)
}
log.Println("Starting grpc server with cloud profiler", "project", projectID, "service", service, "addr", address)
if err := s.Serve(lis); err != nil {
log.Fatalf("Failed to serve grpc, err: %s", err)
}
}