server.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  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
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  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.
  16. *
  17. */
  18. // This binary can only run on Google Cloud Platform (GCP).
  19. package main
  20. import (
  21. "flag"
  22. "net"
  23. grpc "google.golang.org/grpc"
  24. "google.golang.org/grpc/credentials/alts"
  25. "google.golang.org/grpc/grpclog"
  26. "google.golang.org/grpc/interop"
  27. testpb "google.golang.org/grpc/interop/grpc_testing"
  28. )
  29. var (
  30. hsAddr = flag.String("alts_handshaker_service_address", "", "ALTS handshaker gRPC service address")
  31. serverAddr = flag.String("server_address", ":8080", "The port on which the server is listening")
  32. )
  33. func main() {
  34. flag.Parse()
  35. lis, err := net.Listen("tcp", *serverAddr)
  36. if err != nil {
  37. grpclog.Fatalf("gRPC Server: failed to start the server at %v: %v", *serverAddr, err)
  38. }
  39. opts := alts.DefaultServerOptions()
  40. if *hsAddr != "" {
  41. opts.HandshakerServiceAddress = *hsAddr
  42. }
  43. altsTC := alts.NewServerCreds(opts)
  44. grpcServer := grpc.NewServer(grpc.Creds(altsTC))
  45. testpb.RegisterTestServiceServer(grpcServer, interop.NewTestServer())
  46. grpcServer.Serve(lis)
  47. }