func main() { listener, err := net.Listen("tcp", ":1234") if err != nil { grpclog.Fatalf("failed to listen: %v", err) } // Create a gRPC server and attach our service to it server := grpc.NewServer() pb.RegisterTestServer(server, &testService{}) // Start handling requests grpclog.Printf("Starting to listen on %s", listener.Addr()) if err = server.Serve(listener); err != nil { grpclog.Fatalf("failed to serve: %v", err) } }
func main() { listener, err := net.Listen("tcp", ":1234") if err != nil { grpclog.Fatalf("failed to listen: %v", err) } // Serve via TLS creds, err := credentials.NewServerTLSFromFile("server.crt", "server.key") if err != nil { grpclog.Fatalf("Failed to generate credentials %v", err) } opts := []grpc.ServerOption{grpc.Creds(creds)} // Create a gRPC server and attach our service to it server := grpc.NewServer(opts...) pb.RegisterTestServer(server, &testService{}) // Start handling requests grpclog.Printf("Starting to listen on %s", listener.Addr()) if err = server.Serve(listener); err != nil { grpclog.Fatalf("failed to serve: %v", err) } }