...

Source file src/github.com/grpc-ecosystem/grpc-gateway/examples/internal/cmd/example-gateway-server/main.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/examples/internal/cmd/example-gateway-server

     1  /*
     2  Command example-gateway-server is an example reverse-proxy implementation
     3  whose HTTP handler is generated by grpc-gateway.
     4  */
     5  package main
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  
    11  	"github.com/golang/glog"
    12  	"github.com/grpc-ecosystem/grpc-gateway/examples/internal/gateway"
    13  )
    14  
    15  var (
    16  	endpoint   = flag.String("endpoint", "localhost:9090", "endpoint of the gRPC service")
    17  	network    = flag.String("network", "tcp", `one of "tcp" or "unix". Must be consistent to -endpoint`)
    18  	swaggerDir = flag.String("swagger_dir", "examples/internal/proto/examplepb", "path to the directory which contains swagger definitions")
    19  )
    20  
    21  func main() {
    22  	flag.Parse()
    23  	defer glog.Flush()
    24  
    25  	ctx := context.Background()
    26  	opts := gateway.Options{
    27  		Addr: ":8080",
    28  		GRPCServer: gateway.Endpoint{
    29  			Network: *network,
    30  			Addr:    *endpoint,
    31  		},
    32  		SwaggerDir: *swaggerDir,
    33  	}
    34  	if err := gateway.Run(ctx, opts); err != nil {
    35  		glog.Fatal(err)
    36  	}
    37  }
    38  

View as plain text