github.com/0xKiwi/rules_go@v0.24.3/tests/legacy/examples/proto/grpc/main.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"net"
     6  
     7  	pb "github.com/bazelbuild/rules_go/examples/proto/grpc/my_svc_proto"
     8  	lpb "github.com/bazelbuild/rules_go/examples/proto/lib/lib_proto"
     9  	apb "github.com/golang/protobuf/ptypes/any"
    10  	epb "github.com/golang/protobuf/ptypes/empty"
    11  	"golang.org/x/net/context"
    12  	"google.golang.org/grpc"
    13  )
    14  
    15  type server struct{}
    16  
    17  func (s *server) Get(ctx context.Context, req *pb.GetRequest) (*epb.Empty, error) {
    18  	return &epb.Empty{}, nil
    19  }
    20  
    21  func (s *server) Put(ctx context.Context, req *apb.Any) (*lpb.LibObject, error) {
    22  	return &lpb.LibObject{}, nil
    23  }
    24  
    25  func main() {
    26  	lis, err := net.Listen("tcp", ":8080")
    27  	if err != nil {
    28  		log.Fatalf("failed to listen: %v", err)
    29  	}
    30  	s := grpc.NewServer()
    31  	pb.RegisterMyServiceServer(s, &server{})
    32  	s.Serve(lis)
    33  }