3 * Copyright 2014 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 "google.golang.org/grpc"
27 "google.golang.org/grpc/credentials"
28 "google.golang.org/grpc/grpclog"
29 "google.golang.org/grpc/interop"
30 testpb "google.golang.org/grpc/interop/grpc_testing"
31 "google.golang.org/grpc/testdata"
35 useTLS = flag.Bool("use_tls", false, "Connection uses TLS if true, else plain TCP")
36 certFile = flag.String("tls_cert_file", "", "The TLS cert file")
37 keyFile = flag.String("tls_key_file", "", "The TLS key file")
38 port = flag.Int("port", 10000, "The server port")
43 p := strconv.Itoa(*port)
44 lis, err := net.Listen("tcp", ":"+p)
46 grpclog.Fatalf("failed to listen: %v", err)
48 var opts []grpc.ServerOption
51 *certFile = testdata.Path("server1.pem")
54 *keyFile = testdata.Path("server1.key")
56 creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
58 grpclog.Fatalf("Failed to generate credentials %v", err)
60 opts = []grpc.ServerOption{grpc.Creds(creds)}
62 server := grpc.NewServer(opts...)
63 testpb.RegisterTestServiceServer(server, interop.NewTestServer())