github.com/grpc-ecosystem/grpc-gateway/v2@v2.19.1/examples/internal/cmd/example-gateway-server/main.go (about) 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/grpc-ecosystem/grpc-gateway/v2/examples/internal/gateway" 12 "google.golang.org/grpc/grpclog" 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 openAPIDir = flag.String("openapi_dir", "examples/internal/proto/examplepb", "path to the directory which contains OpenAPI definitions") 19 ) 20 21 func main() { 22 flag.Parse() 23 24 ctx := context.Background() 25 opts := gateway.Options{ 26 Addr: ":8080", 27 GRPCServer: gateway.Endpoint{ 28 Network: *network, 29 Addr: *endpoint, 30 }, 31 OpenAPIDir: *openAPIDir, 32 } 33 if err := gateway.Run(ctx, opts); err != nil { 34 grpclog.Fatal(err) 35 } 36 }