diff --git a/Dockerfile.app b/Dockerfile.app index 7d2f0cc7..351bcf30 100644 --- a/Dockerfile.app +++ b/Dockerfile.app @@ -16,6 +16,4 @@ WORKDIR /app COPY --from=build /app/src/bin/ /app/ -RUN ls - ENTRYPOINT ["/app/server"] diff --git a/Makefile b/Makefile index 7794e18a..6efa8940 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,32 @@ pb: -Ithird_party/googleapis \ -Ithird_party/grpc-gateway \ --go_out=plugins=grpc:protos/ \ - --grpc-gateway_out=logtostderr=true:protos/ + --grpc-gateway_out=logtostderr=true:protos/ \ + --include_imports --include_source_info \ + --descriptor_set_out=protos/proto.pb build: - go build -o bin/grpc-service main.go - go build -o bin/gateway gateway/main.go + - go build -o bin/client clients/main.go + +client: + - ./bin/client grpc-service: - ./bin/grpc-service gateway-service: - - ./bin/gateway \ No newline at end of file + - ./bin/gateway + +dc-gateway: + - docker-compose up grpc_gateway grpc_app mongo + +dc-gateway-build: + - docker-compose --build up grpc_gateway grpc_app mongo + +dc-envoy: + - docker-compose up envoy-proxy grpc_app mongo + +dc-envoy-build: + - docker-compose up --build envoy-proxy grpc_app mongo \ No newline at end of file diff --git a/clients/index.html b/clients/index.html new file mode 100644 index 00000000..122677d0 --- /dev/null +++ b/clients/index.html @@ -0,0 +1,31 @@ + + + + + + + + + GRPC chat + + + +
+ +
+ + + + + + \ No newline at end of file diff --git a/clients/main.go b/clients/main.go new file mode 100644 index 00000000..ebd6311d --- /dev/null +++ b/clients/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "context" + "io" + "log" + "os" + + "github.com/joho/godotenv" + pb "github.com/trinhdaiphuc/Example-CRUD-with-Mongo-use-http-transcoding-to-gRPC/protos" + "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/emptypb" +) + +func main() { + var conn *grpc.ClientConn + + err := godotenv.Load() + + conn, err = grpc.Dial(os.Getenv("SERVER_HOST"), grpc.WithInsecure()) + log.Println("Host: ", os.Getenv("SERVER_HOST")) + if err != nil { + log.Fatalf("Did not connect %s ", err) + } + defer conn.Close() + + client := pb.NewEntityServiceClient(conn) + + response, err := client.ListEntities(context.Background(), &emptypb.Empty{}) + + if err != nil { + log.Fatalf("Error when calling ListEntities: %s", err) + } + + for { + entities, err := response.Recv() + if err == io.EOF { + break + } + if err != nil { + log.Fatalf("%v.ListEntities(_) = _, %v", client, err) + } + log.Println(entities) + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 9c6a5c10..e3b47286 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,24 @@ version: "3" services: + envoy-proxy: + image: envoyproxy/envoy-dev + ports: + - 8080:51051 + volumes: + - ./protos/proto.pb:/data/proto.pb + - ./envoy-proxy.yaml:/etc/envoy/envoy.yaml + depends_on: + - grpc_app + environment: + - GRPC_VERBOSITY=debug + grpc_app: build: dockerfile: Dockerfile.app context: . volumes: - - ./server:/app/src/server + - .:/app/src/server depends_on: - mongo ports: @@ -30,11 +42,11 @@ services: - ENTITY_SERVER_HOST=grpc_app:50051 mongo: - image: "mongo:4.2.1" + image: mongo:latest volumes: - - "mongo:/data/db" + - mongo:/data/db ports: - - "27100:27017" + - 27100:27017 volumes: mongo: diff --git a/envoy-proxy.yaml b/envoy-proxy.yaml new file mode 100644 index 00000000..1eecd918 --- /dev/null +++ b/envoy-proxy.yaml @@ -0,0 +1,64 @@ +admin: + access_log_path: /tmp/admin_access.log + address: + socket_address: { address: 0.0.0.0, port_value: 9901 } + +static_resources: + listeners: + - name: service-entity-http-listeners + address: + socket_address: { address: 0.0.0.0, port_value: 51051 } + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager + stat_prefix: grpc_json + codec_type: AUTO + route_config: + name: local_route + virtual_hosts: + - name: local_service + domains: ["*"] + cors: + allow_origin_string_match: + - safe_regex: + google_re2: {} + regex: \* + allow_methods: "GET, POST, PUT, DELETE" + filter_enabled: + default_value: + numerator: 100 + denominator: HUNDRED + runtime_key: cors.www.enabled + shadow_enabled: + default_value: + numerator: 0 + denominator: HUNDRED + runtime_key: cors.www.shadow_enabled + routes: + - match: { prefix: "/entity.EntityService", grpc: {} } + route: { cluster: grpc-backend-services, timeout: { seconds: 60 } } + http_filters: + - name: envoy.filters.http.grpc_json_transcoder + config: + proto_descriptor: "/data/proto.pb" + services: ["entity.EntityService"] + print_options: + add_whitespace: true + always_print_primitive_fields: true + always_print_enums_as_ints: false + preserve_proto_field_names: true + - name: envoy.filters.http.cors + - name: envoy.filters.http.router + + clusters: + - name: grpc-backend-services + connect_timeout: 1.25s + type: logical_dns + lb_policy: round_robin + http2_protocol_options: {} + hosts: + - socket_address: + address: grpc_app + port_value: 50051 diff --git a/protos/entity.pb.go b/protos/entity.pb.go index f959124d..fcc66809 100644 --- a/protos/entity.pb.go +++ b/protos/entity.pb.go @@ -9,6 +9,7 @@ package entity import ( context "context" proto "github.com/golang/protobuf/proto" + empty "github.com/golang/protobuf/ptypes/empty" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -578,74 +579,76 @@ var file_entity_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x60, 0x0a, 0x06, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x0e, - 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x39, 0x0a, 0x0f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, - 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, - 0x79, 0x22, 0x39, 0x0a, 0x0f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, - 0x79, 0x52, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, - 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x49, 0x0a, 0x0f, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x60, 0x0a, 0x06, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x75, 0x72, 0x6c, 0x22, 0x39, 0x0a, 0x0f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, + 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, + 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x39, + 0x0a, 0x0f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, + 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, + 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x49, 0x0a, 0x0f, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x26, 0x0a, 0x06, + 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, + 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x22, 0x39, 0x0a, 0x0f, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, + 0x1f, 0x0a, 0x0d, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, + 0x22, 0x37, 0x0a, 0x0d, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, + 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, + 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x21, 0x0a, 0x0f, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2b, 0x0a, 0x0f, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x12, + 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x11, 0x0a, 0x0f, 0x4c, 0x69, 0x73, + 0x74, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x22, 0x39, 0x0a, 0x0f, + 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x73, 0x12, + 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, - 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x39, 0x0a, 0x0f, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, - 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, - 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x22, 0x1f, 0x0a, 0x0d, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, - 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x64, 0x22, 0x37, 0x0a, 0x0d, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, - 0x79, 0x52, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, - 0x74, 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x21, 0x0a, 0x0f, - 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, - 0x2b, 0x0a, 0x0f, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, - 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x11, 0x0a, 0x0f, - 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x22, - 0x39, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, - 0x65, 0x73, 0x12, 0x26, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x45, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x32, 0xd3, 0x03, 0x0a, 0x0d, 0x45, - 0x6e, 0x74, 0x69, 0x74, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5b, 0x0a, 0x0c, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x2e, 0x65, - 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x22, 0x19, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x22, 0x09, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, - 0x73, 0x3a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x52, 0x0a, 0x0a, 0x52, 0x65, 0x61, - 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x15, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, - 0x2e, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x15, - 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x52, 0x65, 0x73, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, - 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x60, 0x0a, - 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x2e, - 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, - 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x22, - 0x1e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x1a, 0x0e, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, - 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x3a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, - 0x58, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, - 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, - 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, - 0x79, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, - 0x73, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x2a, 0x0e, 0x2f, 0x65, 0x6e, 0x74, 0x69, - 0x74, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x55, 0x0a, 0x0c, 0x4c, 0x69, 0x73, - 0x74, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, - 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x45, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x73, 0x22, 0x11, 0x82, 0xd3, 0xe4, - 0x93, 0x02, 0x0b, 0x12, 0x09, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x30, 0x01, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x32, 0xd2, 0x03, 0x0a, 0x0d, 0x45, 0x6e, 0x74, 0x69, + 0x74, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5b, 0x0a, 0x0c, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, + 0x74, 0x79, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, + 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x22, 0x19, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x13, 0x22, 0x09, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x3a, 0x06, + 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x52, 0x0a, 0x0a, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x12, 0x15, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x52, 0x65, + 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x65, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, + 0x65, 0x73, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x65, 0x6e, 0x74, + 0x69, 0x74, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x60, 0x0a, 0x0c, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x2e, 0x65, 0x6e, 0x74, + 0x69, 0x74, 0x79, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x22, 0x1e, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x18, 0x1a, 0x0e, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2f, + 0x7b, 0x69, 0x64, 0x7d, 0x3a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x58, 0x0a, 0x0c, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x2e, 0x65, + 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, + 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x22, 0x16, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x2a, 0x0e, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, + 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x54, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, + 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, + 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x74, 0x69, + 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x73, 0x22, 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x12, + 0x09, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x30, 0x01, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -673,6 +676,7 @@ var file_entity_proto_goTypes = []interface{}{ (*DeleteEntityRes)(nil), // 8: entity.DeleteEntityRes (*ListEntitiesReq)(nil), // 9: entity.ListEntitiesReq (*ListEntitiesRes)(nil), // 10: entity.ListEntitiesRes + (*empty.Empty)(nil), // 11: google.protobuf.Empty } var file_entity_proto_depIdxs = []int32{ 0, // 0: entity.CreateEntityReq.entity:type_name -> entity.Entity @@ -685,7 +689,7 @@ var file_entity_proto_depIdxs = []int32{ 5, // 7: entity.EntityService.ReadEntity:input_type -> entity.ReadEntityReq 3, // 8: entity.EntityService.UpdateEntity:input_type -> entity.UpdateEntityReq 7, // 9: entity.EntityService.DeleteEntity:input_type -> entity.DeleteEntityReq - 9, // 10: entity.EntityService.ListEntities:input_type -> entity.ListEntitiesReq + 11, // 10: entity.EntityService.ListEntities:input_type -> google.protobuf.Empty 2, // 11: entity.EntityService.CreateEntity:output_type -> entity.CreateEntityRes 6, // 12: entity.EntityService.ReadEntity:output_type -> entity.ReadEntityRes 4, // 13: entity.EntityService.UpdateEntity:output_type -> entity.UpdateEntityRes @@ -873,7 +877,7 @@ type EntityServiceClient interface { ReadEntity(ctx context.Context, in *ReadEntityReq, opts ...grpc.CallOption) (*ReadEntityRes, error) UpdateEntity(ctx context.Context, in *UpdateEntityReq, opts ...grpc.CallOption) (*UpdateEntityRes, error) DeleteEntity(ctx context.Context, in *DeleteEntityReq, opts ...grpc.CallOption) (*DeleteEntityRes, error) - ListEntities(ctx context.Context, in *ListEntitiesReq, opts ...grpc.CallOption) (EntityService_ListEntitiesClient, error) + ListEntities(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (EntityService_ListEntitiesClient, error) } type entityServiceClient struct { @@ -920,7 +924,7 @@ func (c *entityServiceClient) DeleteEntity(ctx context.Context, in *DeleteEntity return out, nil } -func (c *entityServiceClient) ListEntities(ctx context.Context, in *ListEntitiesReq, opts ...grpc.CallOption) (EntityService_ListEntitiesClient, error) { +func (c *entityServiceClient) ListEntities(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (EntityService_ListEntitiesClient, error) { stream, err := c.cc.NewStream(ctx, &_EntityService_serviceDesc.Streams[0], "/entity.EntityService/ListEntities", opts...) if err != nil { return nil, err @@ -958,7 +962,7 @@ type EntityServiceServer interface { ReadEntity(context.Context, *ReadEntityReq) (*ReadEntityRes, error) UpdateEntity(context.Context, *UpdateEntityReq) (*UpdateEntityRes, error) DeleteEntity(context.Context, *DeleteEntityReq) (*DeleteEntityRes, error) - ListEntities(*ListEntitiesReq, EntityService_ListEntitiesServer) error + ListEntities(*empty.Empty, EntityService_ListEntitiesServer) error } // UnimplementedEntityServiceServer can be embedded to have forward compatible implementations. @@ -977,7 +981,7 @@ func (*UnimplementedEntityServiceServer) UpdateEntity(context.Context, *UpdateEn func (*UnimplementedEntityServiceServer) DeleteEntity(context.Context, *DeleteEntityReq) (*DeleteEntityRes, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteEntity not implemented") } -func (*UnimplementedEntityServiceServer) ListEntities(*ListEntitiesReq, EntityService_ListEntitiesServer) error { +func (*UnimplementedEntityServiceServer) ListEntities(*empty.Empty, EntityService_ListEntitiesServer) error { return status.Errorf(codes.Unimplemented, "method ListEntities not implemented") } @@ -1058,7 +1062,7 @@ func _EntityService_DeleteEntity_Handler(srv interface{}, ctx context.Context, d } func _EntityService_ListEntities_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(ListEntitiesReq) + m := new(empty.Empty) if err := stream.RecvMsg(m); err != nil { return err } diff --git a/protos/entity.pb.gw.go b/protos/entity.pb.gw.go index 216da407..b358eac1 100644 --- a/protos/entity.pb.gw.go +++ b/protos/entity.pb.gw.go @@ -15,6 +15,7 @@ import ( "github.com/golang/protobuf/descriptor" "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/ptypes/empty" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/utilities" "google.golang.org/grpc" @@ -244,7 +245,7 @@ func local_request_EntityService_DeleteEntity_0(ctx context.Context, marshaler r } func request_EntityService_ListEntities_0(ctx context.Context, marshaler runtime.Marshaler, client EntityServiceClient, req *http.Request, pathParams map[string]string) (EntityService_ListEntitiesClient, runtime.ServerMetadata, error) { - var protoReq ListEntitiesReq + var protoReq empty.Empty var metadata runtime.ServerMetadata stream, err := client.ListEntities(ctx, &protoReq) diff --git a/protos/entity.proto b/protos/entity.proto index e3fecc20..15654b4c 100644 --- a/protos/entity.proto +++ b/protos/entity.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package entity; import "google/api/annotations.proto"; +import "google/protobuf/empty.proto"; // The entity service definition with http transcoding service EntityService { @@ -28,7 +29,7 @@ service EntityService { delete: "/entities/{id}" }; } - rpc ListEntities(ListEntitiesReq) returns (stream ListEntitiesRes) { + rpc ListEntities(google.protobuf.Empty) returns (stream ListEntitiesRes) { option (google.api.http) = { get: "/entities" }; diff --git a/protos/proto.pb b/protos/proto.pb new file mode 100644 index 00000000..8ae96495 Binary files /dev/null and b/protos/proto.pb differ diff --git a/services/listEntity.go b/services/listEntity.go index 7477f000..ed033e55 100644 --- a/services/listEntity.go +++ b/services/listEntity.go @@ -10,10 +10,11 @@ import ( "go.mongodb.org/mongo-driver/bson" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/emptypb" ) // ListEntities is a gRPC function to list all entities in MongoDB -func (s *EntityServiceServer) ListEntities(req *pb.ListEntitiesReq, stream pb.EntityService_ListEntitiesServer) error { +func (s *EntityServiceServer) ListEntities(req *emptypb.Empty, stream pb.EntityService_ListEntitiesServer) error { // Initiate a EntityItem type to write decoded data to data := &models.EntityItem{} // collection.Find returns a cursor for our (empty) query