MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

examples/features/authentication/server/main.go:49–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47var port = flag.Int("port", 50051, "the port to serve on")
48
49func main() {
50 flag.Parse()
51 fmt.Printf("server starting on port %d...\n", *port)
52
53 cert, err := tls.LoadX509KeyPair(data.Path("x509/server_cert.pem"), data.Path("x509/server_key.pem"))
54 if err != nil {
55 log.Fatalf("failed to load key pair: %s", err)
56 }
57 opts := []grpc.ServerOption{
58 // The following grpc.ServerOption adds an interceptor for all unary
59 // RPCs. To configure an interceptor for streaming RPCs, see:
60 // https://godoc.org/google.golang.org/grpc#StreamInterceptor
61 grpc.UnaryInterceptor(ensureValidToken),
62 // Enable TLS for all incoming connections.
63 grpc.Creds(credentials.NewServerTLSFromCert(&cert)),
64 }
65 s := grpc.NewServer(opts...)
66 pb.RegisterEchoServer(s, &ecServer{})
67 lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
68 if err != nil {
69 log.Fatalf("failed to listen: %v", err)
70 }
71 if err := s.Serve(lis); err != nil {
72 log.Fatalf("failed to serve: %v", err)
73 }
74}
75
76type ecServer struct {
77 pb.UnimplementedEchoServer

Callers

nothing calls this directly

Calls 9

ServeMethod · 0.95
PathFunction · 0.92
UnaryInterceptorFunction · 0.92
CredsFunction · 0.92
NewServerTLSFromCertFunction · 0.92
NewServerFunction · 0.92
ParseMethod · 0.65
PrintfMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected