diff --git a/example/hello-world/go.mod b/example/hello-world/go.mod index 24427fed8..06c12cd4f 100644 --- a/example/hello-world/go.mod +++ b/example/hello-world/go.mod @@ -5,9 +5,5 @@ go 1.12 replace github.com/yourrepo/hello-world-idl => ./hello-world-idl require ( - github.com/grpc-ecosystem/grpc-gateway v1.11.3 // indirect - github.com/yourrepo/hello-world-idl v0.0.0 - google.golang.org/appengine v1.4.0 // indirect - google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143 // indirect - google.golang.org/grpc v1.24.0 // indirect + github.com/yourrepo/hello-world-idl v0.0.0 ) diff --git a/example/hello-world/go.sum b/example/hello-world/go.sum deleted file mode 100644 index 427acc122..000000000 --- a/example/hello-world/go.sum +++ /dev/null @@ -1,54 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/grpc-ecosystem/grpc-gateway v1.11.3 h1:h8+NsYENhxNTuq+dobk3+ODoJtwY4Fu0WQXsxJfL8aM= -github.com/grpc-ecosystem/grpc-gateway v1.11.3/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143 h1:tikhlQEJeezbnu0Zcblj7g5vm/L7xt6g1vnfq8mRCS4= -google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/example/hello-world/hello-world-idl/gen/go/health/health.pb.go b/example/hello-world/hello-world-idl/gen/go/health/health.pb.go index b203ec123..55db31974 100644 --- a/example/hello-world/hello-world-idl/gen/go/health/health.pb.go +++ b/example/hello-world/hello-world-idl/gen/go/health/health.pb.go @@ -10,8 +10,6 @@ import ( _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -240,17 +238,6 @@ type HealthServer interface { Watch(*HealthCheckRequest, Health_WatchServer) error } -// UnimplementedHealthServer can be embedded to have forward compatible implementations. -type UnimplementedHealthServer struct { -} - -func (*UnimplementedHealthServer) Check(ctx context.Context, req *HealthCheckRequest) (*HealthCheckResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Check not implemented") -} -func (*UnimplementedHealthServer) Watch(req *HealthCheckRequest, srv Health_WatchServer) error { - return status.Errorf(codes.Unimplemented, "method Watch not implemented") -} - func RegisterHealthServer(s *grpc.Server, srv HealthServer) { s.RegisterService(&_Health_serviceDesc, srv) } diff --git a/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.go b/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.go index 1fac18020..a0a7f2497 100644 --- a/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.go +++ b/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.go @@ -11,8 +11,6 @@ import ( health "github.com/yourrepo/hello-world-idl/gen/go/health" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -85,14 +83,6 @@ type HelloworldServer interface { Check(context.Context, *health.HealthCheckRequest) (*health.HealthCheckResponse, error) } -// UnimplementedHelloworldServer can be embedded to have forward compatible implementations. -type UnimplementedHelloworldServer struct { -} - -func (*UnimplementedHelloworldServer) Check(ctx context.Context, req *health.HealthCheckRequest) (*health.HealthCheckResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Check not implemented") -} - func RegisterHelloworldServer(s *grpc.Server, srv HelloworldServer) { s.RegisterService(&_Helloworld_serviceDesc, srv) } diff --git a/example/hello-world/hello-world-idl/gen/http/health/health.pb.gw.go b/example/hello-world/hello-world-idl/gen/http/health/health.pb.gw.go new file mode 100644 index 000000000..16fe3bea7 --- /dev/null +++ b/example/hello-world/hello-world-idl/gen/http/health/health.pb.gw.go @@ -0,0 +1,162 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: proto/health/health.proto + +/* +Package health is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package health + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +var ( + filter_Health_Check_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Health_Check_0(ctx context.Context, marshaler runtime.Marshaler, client HealthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq HealthCheckRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Health_Check_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Check(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Health_Check_0(ctx context.Context, marshaler runtime.Marshaler, server HealthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq HealthCheckRequest + var metadata runtime.ServerMetadata + + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Health_Check_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Check(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterHealthHandlerServer registers the http handlers for service Health to "mux". +// UnaryRPC :call HealthServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +func RegisterHealthHandlerServer(ctx context.Context, mux *runtime.ServeMux, server HealthServer) error { + + mux.Handle("GET", pattern_Health_Check_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Health_Check_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Health_Check_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterHealthHandlerFromEndpoint is same as RegisterHealthHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterHealthHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterHealthHandler(ctx, mux, conn) +} + +// RegisterHealthHandler registers the http handlers for service Health to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterHealthHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterHealthHandlerClient(ctx, mux, NewHealthClient(conn)) +} + +// RegisterHealthHandlerClient registers the http handlers for service Health +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "HealthClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "HealthClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "HealthClient" to call the correct interceptors. +func RegisterHealthHandlerClient(ctx context.Context, mux *runtime.ServeMux, client HealthClient) error { + + mux.Handle("GET", pattern_Health_Check_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Health_Check_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Health_Check_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Health_Check_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "health"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Health_Check_0 = runtime.ForwardResponseMessage +) diff --git a/example/hello-world/hello-world-idl/gen/http/health/health.swagger.json b/example/hello-world/hello-world-idl/gen/http/health/health.swagger.json new file mode 100644 index 000000000..5ecef0a83 --- /dev/null +++ b/example/hello-world/hello-world-idl/gen/http/health/health.swagger.json @@ -0,0 +1,117 @@ +{ + "swagger": "2.0", + "info": { + "title": "Health Checks", + "version": "1.0" + }, + "schemes": [ + "http", + "https" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/health": { + "get": { + "operationId": "Check", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/healthHealthCheckResponse" + } + } + }, + "parameters": [ + { + "name": "service", + "in": "query", + "required": false, + "type": "string" + } + ], + "tags": [ + "Health" + ] + } + } + }, + "definitions": { + "HealthCheckResponseServingStatus": { + "type": "string", + "enum": [ + "UNKNOWN", + "SERVING", + "NOT_SERVING", + "SERVICE_UNKNOWN" + ], + "default": "UNKNOWN" + }, + "healthHealthCheckResponse": { + "type": "object", + "properties": { + "status": { + "$ref": "#/definitions/HealthCheckResponseServingStatus" + } + } + }, + "protobufAny": { + "type": "object", + "properties": { + "type_url": { + "type": "string", + "description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics." + }, + "value": { + "type": "string", + "format": "byte", + "description": "Must be a valid serialized protocol buffer of the above specified type." + } + }, + "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" + }, + "runtimeStreamError": { + "type": "object", + "properties": { + "grpc_code": { + "type": "integer", + "format": "int32" + }, + "http_code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "http_status": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + }, + "x-stream-definitions": { + "healthHealthCheckResponse": { + "type": "object", + "properties": { + "result": { + "$ref": "#/definitions/healthHealthCheckResponse" + }, + "error": { + "$ref": "#/definitions/runtimeStreamError" + } + }, + "title": "Stream result of healthHealthCheckResponse" + } + } +} diff --git a/example/hello-world/hello-world-idl/gen/http/helloworld/helloworld.pb.gw.go b/example/hello-world/hello-world-idl/gen/http/helloworld/helloworld.pb.gw.go new file mode 100644 index 000000000..1e17d4153 --- /dev/null +++ b/example/hello-world/hello-world-idl/gen/http/helloworld/helloworld.pb.gw.go @@ -0,0 +1,163 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: proto/helloworld/helloworld.proto + +/* +Package helloworld is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package helloworld + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "github.com/yourrepo/hello-world-idl/gen/go/health" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +var ( + filter_Helloworld_Check_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Helloworld_Check_0(ctx context.Context, marshaler runtime.Marshaler, client HelloworldClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq health.HealthCheckRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Helloworld_Check_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Check(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Helloworld_Check_0(ctx context.Context, marshaler runtime.Marshaler, server HelloworldServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq health.HealthCheckRequest + var metadata runtime.ServerMetadata + + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Helloworld_Check_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Check(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterHelloworldHandlerServer registers the http handlers for service Helloworld to "mux". +// UnaryRPC :call HelloworldServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +func RegisterHelloworldHandlerServer(ctx context.Context, mux *runtime.ServeMux, server HelloworldServer) error { + + mux.Handle("GET", pattern_Helloworld_Check_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Helloworld_Check_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Helloworld_Check_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterHelloworldHandlerFromEndpoint is same as RegisterHelloworldHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterHelloworldHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterHelloworldHandler(ctx, mux, conn) +} + +// RegisterHelloworldHandler registers the http handlers for service Helloworld to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterHelloworldHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterHelloworldHandlerClient(ctx, mux, NewHelloworldClient(conn)) +} + +// RegisterHelloworldHandlerClient registers the http handlers for service Helloworld +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "HelloworldClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "HelloworldClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "HelloworldClient" to call the correct interceptors. +func RegisterHelloworldHandlerClient(ctx context.Context, mux *runtime.ServeMux, client HelloworldClient) error { + + mux.Handle("GET", pattern_Helloworld_Check_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Helloworld_Check_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Helloworld_Check_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Helloworld_Check_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "helloworld", "health"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Helloworld_Check_0 = runtime.ForwardResponseMessage +) diff --git a/example/hello-world/hello-world-idl/gen/http/helloworld/helloworld.swagger.json b/example/hello-world/hello-world-idl/gen/http/helloworld/helloworld.swagger.json new file mode 100644 index 000000000..daf0e175e --- /dev/null +++ b/example/hello-world/hello-world-idl/gen/http/helloworld/helloworld.swagger.json @@ -0,0 +1,63 @@ +{ + "swagger": "2.0", + "info": { + "title": "Helloworld", + "version": "1.0" + }, + "schemes": [ + "http", + "https" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/helloworld/health": { + "get": { + "operationId": "Check", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/healthHealthCheckResponse" + } + } + }, + "parameters": [ + { + "name": "service", + "in": "query", + "required": false, + "type": "string" + } + ], + "tags": [ + "Helloworld" + ] + } + } + }, + "definitions": { + "HealthCheckResponseServingStatus": { + "type": "string", + "enum": [ + "UNKNOWN", + "SERVING", + "NOT_SERVING", + "SERVICE_UNKNOWN" + ], + "default": "UNKNOWN" + }, + "healthHealthCheckResponse": { + "type": "object", + "properties": { + "status": { + "$ref": "#/definitions/HealthCheckResponseServingStatus" + } + } + } + } +} diff --git a/example/hello-world/hello-world-idl/gen/web/health/healthServiceClientPb.ts b/example/hello-world/hello-world-idl/gen/web/health/healthServiceClientPb.ts new file mode 100644 index 000000000..d9f55f41a --- /dev/null +++ b/example/hello-world/hello-world-idl/gen/web/health/healthServiceClientPb.ts @@ -0,0 +1,80 @@ +/** + * @fileoverview gRPC-Web generated client stub for health + * @enhanceable + * @public + */ + +// GENERATED CODE -- DO NOT EDIT! + + +import * as grpcWeb from 'grpc-web'; + +import * as google_api_annotations_pb from '../../google/api/annotations_pb'; +import * as protoc$gen$swagger_options_annotations_pb from '../../protoc-gen-swagger/options/annotations_pb'; + +import { + HealthCheckRequest, + HealthCheckResponse} from './health_pb'; + +export class HealthClient { + client_: grpcWeb.AbstractClientBase; + hostname_: string; + credentials_: null | { [index: string]: string; }; + options_: null | { [index: string]: string; }; + + constructor (hostname: string, + credentials?: null | { [index: string]: string; }, + options?: null | { [index: string]: string; }) { + if (!options) options = {}; + if (!credentials) credentials = {}; + options['format'] = 'text'; + + this.client_ = new grpcWeb.GrpcWebClientBase(options); + this.hostname_ = hostname; + this.credentials_ = credentials; + this.options_ = options; + } + + methodInfoCheck = new grpcWeb.AbstractClientBase.MethodInfo( + HealthCheckResponse, + (request: HealthCheckRequest) => { + return request.serializeBinary(); + }, + HealthCheckResponse.deserializeBinary + ); + + check( + request: HealthCheckRequest, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.Error, + response: HealthCheckResponse) => void) { + return this.client_.rpcCall( + this.hostname_ + + '/health.Health/Check', + request, + metadata || {}, + this.methodInfoCheck, + callback); + } + + methodInfoWatch = new grpcWeb.AbstractClientBase.MethodInfo( + HealthCheckResponse, + (request: HealthCheckRequest) => { + return request.serializeBinary(); + }, + HealthCheckResponse.deserializeBinary + ); + + watch( + request: HealthCheckRequest, + metadata?: grpcWeb.Metadata) { + return this.client_.serverStreaming( + this.hostname_ + + '/health.Health/Watch', + request, + metadata || {}, + this.methodInfoWatch); + } + +} + diff --git a/example/hello-world/hello-world-idl/gen/web/helloworld/helloworldServiceClientPb.ts b/example/hello-world/hello-world-idl/gen/web/helloworld/helloworldServiceClientPb.ts new file mode 100644 index 000000000..e3cabaaa2 --- /dev/null +++ b/example/hello-world/hello-world-idl/gen/web/helloworld/helloworldServiceClientPb.ts @@ -0,0 +1,58 @@ +/** + * @fileoverview gRPC-Web generated client stub for helloworld + * @enhanceable + * @public + */ + +// GENERATED CODE -- DO NOT EDIT! + + +import * as grpcWeb from 'grpc-web'; + +import * as proto_health_health_pb from '../../proto/health/health_pb'; +import * as google_api_annotations_pb from '../../google/api/annotations_pb'; +import * as protoc$gen$swagger_options_annotations_pb from '../../protoc-gen-swagger/options/annotations_pb'; + +export class HelloworldClient { + client_: grpcWeb.AbstractClientBase; + hostname_: string; + credentials_: null | { [index: string]: string; }; + options_: null | { [index: string]: string; }; + + constructor (hostname: string, + credentials?: null | { [index: string]: string; }, + options?: null | { [index: string]: string; }) { + if (!options) options = {}; + if (!credentials) credentials = {}; + options['format'] = 'text'; + + this.client_ = new grpcWeb.GrpcWebClientBase(options); + this.hostname_ = hostname; + this.credentials_ = credentials; + this.options_ = options; + } + + methodInfoCheck = new grpcWeb.AbstractClientBase.MethodInfo( + proto_health_health_pb.HealthCheckResponse, + (request: proto_health_health_pb.HealthCheckRequest) => { + return request.serializeBinary(); + }, + proto_health_health_pb.HealthCheckResponse.deserializeBinary + ); + + check( + request: proto_health_health_pb.HealthCheckRequest, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.Error, + response: proto_health_health_pb.HealthCheckResponse) => void) { + return this.client_.rpcCall( + this.hostname_ + + '/helloworld.Helloworld/Check', + request, + metadata || {}, + this.methodInfoCheck, + callback); + } + +} +