diff --git a/example/hello-world/hello-world-idl/Makefile b/example/hello-world/hello-world-idl/Makefile index 33530a38e..77fe418f4 100644 --- a/example/hello-world/hello-world-idl/Makefile +++ b/example/hello-world/hello-world-idl/Makefile @@ -31,20 +31,17 @@ generate: generate-grpc generate-web generate-http generate-grpc: mkdir -p gen/go protoc ${PROTO_SOURCES} --go_out=plugins=grpc,paths=source_relative:proto ./proto/health/*.proto - protoc ${PROTO_SOURCES} --go_out=plugins=grpc,paths=source_relative:proto ./proto/helloworld/*.proto cp -f -rv proto/proto/* gen/go rm -rf proto/proto generate-web: mkdir -p gen/web protoc ${PROTO_SOURCES} --grpc-web_out=import_style=typescript,mode=grpcwebtext:proto ./proto/health/*.proto - protoc ${PROTO_SOURCES} --grpc-web_out=import_style=typescript,mode=grpcwebtext:proto ./proto/helloworld/*.proto cp -f -rv proto/proto/* gen/web cp -f -rv proto/Proto/* gen/web rm -rf proto/proto proto/Proto generate-http: mkdir -p gen/go protoc ${PROTO_SOURCES} --grpc-gateway_out=logtostderr=true,paths=source_relative:proto --swagger_out=logtostderr=true:proto ./proto/health/*.proto - protoc ${PROTO_SOURCES} --grpc-gateway_out=logtostderr=true,paths=source_relative:proto --swagger_out=logtostderr=true:proto ./proto/helloworld/*.proto cp -f -rv proto/proto/* gen/go rm -rf proto/proto 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 deleted file mode 100644 index a0a7f2497..000000000 --- a/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.go +++ /dev/null @@ -1,119 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/helloworld/helloworld.proto - -package helloworld - -import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options" - health "github.com/yourrepo/hello-world-idl/gen/go/health" - _ "google.golang.org/genproto/googleapis/api/annotations" - grpc "google.golang.org/grpc" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -func init() { proto.RegisterFile("proto/helloworld/helloworld.proto", fileDescriptor_d16ac54e3a89a4f6) } - -var fileDescriptor_d16ac54e3a89a4f6 = []byte{ - // 229 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2c, 0x28, 0xca, 0x2f, - 0xc9, 0xd7, 0xcf, 0x48, 0xcd, 0xc9, 0xc9, 0x2f, 0xcf, 0x2f, 0xca, 0x49, 0x41, 0x62, 0xea, 0x81, - 0xe5, 0x84, 0xb8, 0x10, 0x22, 0x52, 0x92, 0x30, 0xe5, 0x89, 0x39, 0x25, 0x19, 0x50, 0x0a, 0xa2, - 0x4c, 0x4a, 0x26, 0x3d, 0x3f, 0x3f, 0x3d, 0x27, 0x55, 0x3f, 0xb1, 0x20, 0x53, 0x3f, 0x31, 0x2f, - 0x2f, 0xbf, 0x24, 0xb1, 0x24, 0x33, 0x3f, 0xaf, 0x18, 0x2a, 0xab, 0x03, 0xa6, 0x92, 0x75, 0xd3, - 0x53, 0xf3, 0x74, 0x8b, 0xcb, 0x13, 0xd3, 0xd3, 0x53, 0x8b, 0xf4, 0xf3, 0x0b, 0xc0, 0x2a, 0x30, - 0x55, 0x1b, 0xe5, 0x72, 0x71, 0x79, 0xc0, 0x2d, 0x15, 0x8a, 0xe7, 0x62, 0x75, 0xce, 0x48, 0x4d, - 0xce, 0x16, 0x92, 0xd2, 0x83, 0xda, 0xe8, 0x01, 0xa6, 0xc0, 0x82, 0x41, 0xa9, 0x85, 0xa5, 0xa9, - 0xc5, 0x25, 0x52, 0xd2, 0x58, 0xe5, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x95, 0x64, 0x9b, 0x2e, - 0x3f, 0x99, 0xcc, 0x24, 0x2e, 0x24, 0xaa, 0x5f, 0x66, 0x88, 0xea, 0x57, 0x90, 0x5a, 0x27, 0xdf, - 0x49, 0x8e, 0xc2, 0x42, 0x82, 0xc8, 0x76, 0x1a, 0x31, 0x1b, 0xea, 0x19, 0x44, 0x99, 0xa6, 0x67, - 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x57, 0xe6, 0x97, 0x16, 0x15, 0xa5, 0x16, - 0x40, 0x83, 0x4a, 0x17, 0xac, 0x4a, 0x37, 0x33, 0x25, 0x47, 0x3f, 0x3d, 0x35, 0x4f, 0x3f, 0x1d, - 0x39, 0x04, 0x93, 0xd8, 0xc0, 0x9e, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x7a, 0x4e, - 0x9a, 0x5c, 0x01, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// HelloworldClient is the client API for Helloworld service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type HelloworldClient interface { - Check(ctx context.Context, in *health.HealthCheckRequest, opts ...grpc.CallOption) (*health.HealthCheckResponse, error) -} - -type helloworldClient struct { - cc *grpc.ClientConn -} - -func NewHelloworldClient(cc *grpc.ClientConn) HelloworldClient { - return &helloworldClient{cc} -} - -func (c *helloworldClient) Check(ctx context.Context, in *health.HealthCheckRequest, opts ...grpc.CallOption) (*health.HealthCheckResponse, error) { - out := new(health.HealthCheckResponse) - err := c.cc.Invoke(ctx, "/helloworld.Helloworld/Check", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// HelloworldServer is the server API for Helloworld service. -type HelloworldServer interface { - Check(context.Context, *health.HealthCheckRequest) (*health.HealthCheckResponse, error) -} - -func RegisterHelloworldServer(s *grpc.Server, srv HelloworldServer) { - s.RegisterService(&_Helloworld_serviceDesc, srv) -} - -func _Helloworld_Check_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(health.HealthCheckRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(HelloworldServer).Check(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/helloworld.Helloworld/Check", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(HelloworldServer).Check(ctx, req.(*health.HealthCheckRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Helloworld_serviceDesc = grpc.ServiceDesc{ - ServiceName: "helloworld.Helloworld", - HandlerType: (*HelloworldServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Check", - Handler: _Helloworld_Check_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "proto/helloworld/helloworld.proto", -} diff --git a/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.gw.go b/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.gw.go deleted file mode 100644 index 1e17d4153..000000000 --- a/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.gw.go +++ /dev/null @@ -1,163 +0,0 @@ -// 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/go/helloworld/helloworld.swagger.json b/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.swagger.json deleted file mode 100644 index daf0e175e..000000000 --- a/example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.swagger.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "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/helloworld/helloworldServiceClientPb.ts b/example/hello-world/hello-world-idl/gen/web/helloworld/helloworldServiceClientPb.ts deleted file mode 100644 index e3cabaaa2..000000000 --- a/example/hello-world/hello-world-idl/gen/web/helloworld/helloworldServiceClientPb.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @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); - } - -} - diff --git a/example/hello-world/hello-world-idl/gen/web/helloworld/helloworld_pb.d.ts b/example/hello-world/hello-world-idl/gen/web/helloworld/helloworld_pb.d.ts deleted file mode 100644 index 9e09300a8..000000000 --- a/example/hello-world/hello-world-idl/gen/web/helloworld/helloworld_pb.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as jspb from "google-protobuf" - -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'; - diff --git a/example/hello-world/hello-world-idl/proto/helloworld/helloworld.proto b/example/hello-world/hello-world-idl/proto/helloworld/helloworld.proto deleted file mode 100644 index ce1ce7645..000000000 --- a/example/hello-world/hello-world-idl/proto/helloworld/helloworld.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -option go_package = "github.com/yourrepo/hello-world-idl/gen/go/helloworld"; - -package helloworld; - -import "proto/health/health.proto"; -import "google/api/annotations.proto"; -import "protoc-gen-swagger/options/annotations.proto"; - -option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { - info: { - title: "Helloworld"; - version: "1.0"; - } -}; - -service Helloworld { - rpc Check(health.HealthCheckRequest) returns (health.HealthCheckResponse){ - option (google.api.http) = { - get: "/v1/helloworld/health" - }; - } -} diff --git a/example/hello-world/http/main.go b/example/hello-world/http/main.go index 903cb39ed..c4c367040 100644 --- a/example/hello-world/http/main.go +++ b/example/hello-world/http/main.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc" health "github.com/yourrepo/hello-world-idl/gen/go/health" - helloworld "github.com/yourrepo/hello-world-idl/gen/go/helloworld" ) func run(endpoint string, listening string) error { @@ -21,7 +20,6 @@ func run(endpoint string, listening string) error { mux := runtime.NewServeMux() opts := []grpc.DialOption{grpc.WithInsecure()} err := health.RegisterHealthHandlerFromEndpoint(ctx, mux, endpoint, opts) - err = helloworld.RegisterHelloworldHandlerFromEndpoint(ctx, mux, endpoint, opts) if err != nil { return err diff --git a/example/hello-world/main.go b/example/hello-world/main.go index 942274b8d..482f05e66 100644 --- a/example/hello-world/main.go +++ b/example/hello-world/main.go @@ -4,10 +4,8 @@ import ( "net" healthpb "github.com/yourrepo/hello-world-idl/gen/go/health" - helloworldpb "github.com/yourrepo/hello-world-idl/gen/go/helloworld" health "github.com/yourrepo/hello-world/server/health" - helloworld "github.com/yourrepo/hello-world/server/helloworld" "google.golang.org/grpc" ) @@ -24,8 +22,6 @@ func main() { //Server initialization & registration healthServer := health.NewHealthServer() healthpb.RegisterHealthServer(s, healthServer) - helloworldServer := helloworld.NewHelloworldServer() - helloworldpb.RegisterHelloworldServer(s, helloworldServer) log.Printf("Starting grpc server on %v...", grpcAddr) diff --git a/example/hello-world/server/helloworld/helloworld.go b/example/hello-world/server/helloworld/helloworld.go deleted file mode 100644 index f8cded13b..000000000 --- a/example/hello-world/server/helloworld/helloworld.go +++ /dev/null @@ -1,22 +0,0 @@ -package helloworld - -import ( - "context" - health_api "github.com/yourrepo/hello-world-idl/gen/go/health" - //api "github.com/yourrepo/hello-world-idl/gen/go/helloworld" -) - -type HelloworldServer struct { - -} - -func NewHelloworldServer() *HelloworldServer { - return &HelloworldServer{} -} - -func (s *HelloworldServer) Check(ctx context.Context, req *health_api.HealthCheckRequest) (*health_api.HealthCheckResponse, error) { - resp := &health_api.HealthCheckResponse{ - Status: health_api.HealthCheckResponse_SERVING, - } - return resp,nil -} diff --git a/example/hello-world/sprout.yml b/example/hello-world/sprout.yml index 8192e2d54..1546d9b7f 100644 --- a/example/hello-world/sprout.yml +++ b/example/hello-world/sprout.yml @@ -20,5 +20,3 @@ network: services: - - name: helloworld - description: Hello world!. diff --git a/templates/sprout/sprout.tmpl b/templates/sprout/sprout.tmpl index 39bbc05ad..e73129bc5 100644 --- a/templates/sprout/sprout.tmpl +++ b/templates/sprout/sprout.tmpl @@ -20,5 +20,3 @@ network: services: - - name: helloworld - description: Hello world!.