...

Source file src/github.com/google/s2a-go/example/server/server.go

Documentation: github.com/google/s2a-go/example/server

     1  /*
     2   *
     3   * Copyright 2022 Google LLC
     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   *     https://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  
    19  // Package main runs an Echo service.
    20  package main
    21  
    22  import (
    23  	"flag"
    24  	"log"
    25  	"net"
    26  
    27  	"github.com/google/s2a-go"
    28  	"github.com/google/s2a-go/example/echo"
    29  	"google.golang.org/grpc"
    30  
    31  	pb "github.com/google/s2a-go/example/proto/echo_go_proto"
    32  )
    33  
    34  var (
    35  	port    = flag.String("port", ":8080", "Echo service address port.")
    36  	s2aAddr = flag.String("s2a_addr", "0.0.0.0:61365", "S2A service address.")
    37  )
    38  
    39  func runServer(listenPort *string) {
    40  	creds, err := s2a.NewServerCreds(&s2a.ServerOptions{
    41  		S2AAddress:       *s2aAddr,
    42  		VerificationMode: s2a.ConnectToGoogle,
    43  		LocalIdentities:  []s2a.Identity{s2a.NewHostname("test_rsa_server_identity")},
    44  	})
    45  	if err != nil {
    46  		log.Fatalf("NewClientCreds() failed: %v", err)
    47  	}
    48  	listener, err := net.Listen("tcp", *port)
    49  	if err != nil {
    50  		log.Fatalf("Failed to listen on addres %s: %v", *port, err)
    51  	}
    52  	s := grpc.NewServer(grpc.Creds(creds))
    53  	log.Printf("Server: started gRPC Echo Server at: %s", *port)
    54  	pb.RegisterEchoServer(s, &echo.Server{})
    55  	if err := s.Serve(listener); err != nil {
    56  		log.Fatalf("Failed to serve: %v", err)
    57  	}
    58  }
    59  
    60  func main() {
    61  	runServer(port)
    62  }
    63  

View as plain text