From 8f87289d385f4a21d51c7a63d0c34aec5e1e70df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Giovanni=20Jules?= Date: Mon, 6 Jun 2022 02:18:31 +0400 Subject: [PATCH] refactor: use grpc-gateway to register http deck service --- .github/workflows/release_build.yml | 1 - .gitignore | 4 +- README.md | 25 +- buf.gen.yaml | 13 +- buf.lock | 11 + buf.yaml | 3 + cmd/serve.go | 50 +- docs/docs.go | 399 ---------- docs/swagger.json | 374 --------- docs/swagger.yaml | 254 ------ go.mod | 10 +- go.sum | 18 +- magefile.go | 5 - main.go | 11 - repo/inmemory/inmemory.go | 2 +- tools/tools.go | 11 + transport/{grpc => }/deck_service.go | 48 +- transport/grpc/deck_service.pb.go | 648 --------------- transport/grpc/deck_service.proto | 59 -- transport/{grpc/server.go => grpc_server.go} | 28 +- transport/http/card.go | 31 - transport/http/deck.go | 39 - transport/http/errors.go | 7 - transport/http/handler.go | 262 ------ transport/http_handler.go | 31 + transport/{http/server.go => http_server.go} | 69 +- transport/{http => }/success.go | 2 +- transport/transport.go | 42 - transport/{grpc => v1}/deck.pb.go | 129 +-- transport/{grpc => v1}/deck.proto | 4 +- transport/v1/deck.swagger.json | 43 + transport/v1/deck_service.pb.go | 751 ++++++++++++++++++ transport/v1/deck_service.pb.gw.go | 494 ++++++++++++ transport/v1/deck_service.proto | 262 ++++++ transport/v1/deck_service.swagger.json | 361 +++++++++ .../{grpc => v1}/deck_service_grpc.pb.go | 24 +- 36 files changed, 2208 insertions(+), 2317 deletions(-) create mode 100644 buf.lock delete mode 100644 docs/docs.go delete mode 100644 docs/swagger.json delete mode 100644 docs/swagger.yaml create mode 100644 tools/tools.go rename transport/{grpc => }/deck_service.go (79%) delete mode 100644 transport/grpc/deck_service.pb.go delete mode 100644 transport/grpc/deck_service.proto rename transport/{grpc/server.go => grpc_server.go} (62%) delete mode 100644 transport/http/card.go delete mode 100644 transport/http/deck.go delete mode 100644 transport/http/errors.go delete mode 100644 transport/http/handler.go create mode 100644 transport/http_handler.go rename transport/{http/server.go => http_server.go} (56%) rename transport/{http => }/success.go (91%) delete mode 100644 transport/transport.go rename transport/{grpc => v1}/deck.pb.go (56%) rename transport/{grpc => v1}/deck.proto (83%) create mode 100644 transport/v1/deck.swagger.json create mode 100644 transport/v1/deck_service.pb.go create mode 100644 transport/v1/deck_service.pb.gw.go create mode 100644 transport/v1/deck_service.proto create mode 100644 transport/v1/deck_service.swagger.json rename transport/{grpc => v1}/deck_service_grpc.pb.go (92%) diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index d55dd73..607fb70 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -22,7 +22,6 @@ jobs: - name: Set up extra tools run: | - go install github.com/swaggo/swag/cmd/swag@latest go install github.com/magefile/mage@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest go install github.com/onsi/ginkgo/v2/ginkgo@latest diff --git a/.gitignore b/.gitignore index 10bae86..c396e15 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,5 @@ # Kreya *.krproj -transport/grpc/DeckService -transport/grpc/DeckService/* \ No newline at end of file +transport/DeckService +transport/DeckService/* \ No newline at end of file diff --git a/README.md b/README.md index f9a1deb..a11518c 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,13 @@ Deckr provides a REST/gRPC API to simulate a deck of cards. - [Requirements](#requirements) - [Mage Targets](#mage-targets) - [Example](#example) - - [Generate docs](#generate-docs) - [Generate stubs from proto files](#generate-stubs-from-proto-files) - [Run tests with race detector](#run-tests-with-race-detector) - [Build deckr for MacOS M1](#build-deckr-for-macos-m1) - [Install](#install) - [Usage](#usage) - - [REST/gRPC API server](#rest-api-server) - - [REST/gRPC API documentation](#rest-api-documentation) + - [REST/gRPC API server](#restgrpc-api-server) + - [REST API documentation](#rest-api-documentation) - [License](#license) ## Requirements @@ -44,12 +43,6 @@ Deckr provides a REST/gRPC API to simulate a deck of cards. ```shell $ go install github.com/onsi/ginkgo/v2/ginkgo@latest ``` - -- [Swag](https://github.com/swaggo/swag) - Generate REST/gRPC API documentation. - - ```shell - $ go install github.com/swaggo/swag/cmd/swag@latest - ``` - [Buf](https://github.com/bufbuild/buf) - A new way of working with Protocol Buffers. @@ -89,7 +82,6 @@ Targets: build:macOSAmd64 Builds for MacOS 64bit build:macOSArm64 Builds for MacOS M1 build:winAmd64 Builds for Windows 64bit - docs Generates docs lint Run golangci linters proto Generate stubs from proto files test Run tests @@ -99,12 +91,6 @@ Targets: ### Example -#### Generate docs - -```shell -$ mage -v docs -``` - #### Generate stubs from proto files ```shell @@ -187,14 +173,15 @@ USAGE: OPTIONS: --debug whether running in PROD or DEBUG mode (default: false) [$DECKR_DEBUG] - --server-uri value URI of server (default: "http://localhost:9000") [$DECKR_SERVER_URI] + --server-host value HOST of server (default: "localhost") [$DECKR_SERVER_HOST] + --server-port value PORT of server (default: 9000) [$DECKR_SERVER_PORT] --storage-uri value URI of storage (default: "inmemory://") [$DECKR_STORAGE_URI] --help, -h show help (default: false) ``` -## REST/gRPC API documentation +## REST API documentation -The REST/gRPC API documentation is generated using Swag and is available at `/swagger/index.html`. +The REST API documentation is generated using Swag and is available at `/swagger/index.html`. ## License diff --git a/buf.gen.yaml b/buf.gen.yaml index ad54790..2936c45 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -1,9 +1,16 @@ # Documentation: https://docs.buf.build/configuration/v1/buf-gen-yaml version: v1 plugins: - - name: go # Synonym with: protoc-gen- + - name: go out: . opt: paths=source_relative - - name: go-grpc # Synonym with: protoc-gen- + - name: go-grpc out: . - opt: paths=source_relative \ No newline at end of file + opt: paths=source_relative + - name: grpc-gateway + out: . + opt: + - paths=source_relative + - generate_unbound_methods=true + - name: openapiv2 + out: . \ No newline at end of file diff --git a/buf.lock b/buf.lock new file mode 100644 index 0000000..2324d6c --- /dev/null +++ b/buf.lock @@ -0,0 +1,11 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: googleapis + repository: googleapis + commit: cf209eca30404c41a80fec3caba9903f + - remote: buf.build + owner: grpc-ecosystem + repository: grpc-gateway + commit: 00116f302b12478b85deb33b734e026c diff --git a/buf.yaml b/buf.yaml index 1a51945..dfcb904 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,4 +1,7 @@ version: v1 +deps: + - buf.build/googleapis/googleapis + - buf.build/grpc-ecosystem/grpc-gateway breaking: use: - FILE diff --git a/cmd/serve.go b/cmd/serve.go index 547f363..0cc5df8 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -13,6 +13,7 @@ import ( "github.com/mgjules/deckr/repo" "github.com/mgjules/deckr/transport" "github.com/urfave/cli/v2" + "golang.org/x/sync/errgroup" ) var serve = &cli.Command{ @@ -26,10 +27,16 @@ var serve = &cli.Command{ EnvVars: []string{"DECKR_DEBUG"}, }, &cli.StringFlag{ - Name: "server-uri", - Value: "http://localhost:9000", - Usage: "URI of server", - EnvVars: []string{"DECKR_SERVER_URI"}, + Name: "server-host", + Value: "localhost", + Usage: "HOST of server", + EnvVars: []string{"DECKR_SERVER_HOST"}, + }, + &cli.IntFlag{ + Name: "server-port", + Value: 9000, + Usage: "PORT of server", + EnvVars: []string{"DECKR_SERVER_PORT"}, }, &cli.StringFlag{ Name: "storage-uri", @@ -67,13 +74,20 @@ var serve = &cli.Command{ return fmt.Errorf("migrate repository: %w", err) } - transporter, err := transport.NewTransporter(debug, c.String("server-uri"), log, info, repository) - if err != nil { - return fmt.Errorf("new transporter: %w", err) - } + host := c.String("server-host") + port := c.Int("server-port") + grpcServer := transport.NewGRPCServer(host, port, log, repository) + httpServer := transport.NewHTTPServer(debug, host, port+1, log, info) + go func() { - if err := transporter.Start(); err != nil { - log.Errorf("start transporter: %w", err) + if err = grpcServer.Start(); err != nil { + log.Errorf("start grpc server: %w", err) + } + }() + + go func() { + if err = httpServer.Start(); err != nil { + log.Errorf("start http server: %w", err) } }() @@ -84,10 +98,20 @@ var serve = &cli.Command{ ctx, cancel := context.WithTimeout(c.Context, 5*time.Second) defer cancel() - if err := transporter.Stop(ctx); err != nil { - return fmt.Errorf("stop transporter: %w", err) + g, ctx := errgroup.WithContext(ctx) + + g.Go(func() error { + return grpcServer.Stop(ctx) + }) + + g.Go(func() error { + return httpServer.Stop(ctx) + }) + + if err = g.Wait(); err != nil { + return fmt.Errorf("wait for servers to stop: %w", err) } - return nil + return err }, } diff --git a/docs/docs.go b/docs/docs.go deleted file mode 100644 index 38e144e..0000000 --- a/docs/docs.go +++ /dev/null @@ -1,399 +0,0 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag -package docs - -import "github.com/swaggo/swag" - -const docTemplate = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{escape .Description}}", - "title": "{{.Title}}", - "contact": { - "name": "Michaël Giovanni Jules", - "url": "https://mgjules.dev", - "email": "julesmichaelgiovanni@gmail.com" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": { - "/": { - "get": { - "description": "checks if server is running", - "produces": [ - "application/json" - ], - "tags": [ - "core" - ], - "summary": "Health Check", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - } - } - } - }, - "/decks": { - "post": { - "description": "creates a new full or partial deck of cards given an optional list of codes", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "creates a new deck of cards", - "parameters": [ - { - "type": "array", - "items": { - "type": "string" - }, - "example": "AS, 2C, 3D, 4H, 5S", - "description": "list of codes", - "name": "codes", - "in": "query" - }, - { - "type": "array", - "items": { - "type": "string" - }, - "example": "french, uno", - "description": "composition of deck", - "name": "comp", - "in": "query" - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/http.DeckClosed" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/decks/{id}": { - "get": { - "description": "opens a deck of cards given an id", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "opens a deck of cards", - "parameters": [ - { - "type": "string", - "example": "9302b603-13bb-5275-a3b9-5fcefafa34e0", - "description": "id of deck", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.DeckOpened" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/decks/{id}/draw": { - "patch": { - "description": "draws cards from a deck of cards given an id and the number of cards", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "draws cards from a deck of cards", - "parameters": [ - { - "type": "string", - "example": "9302b603-13bb-5275-a3b9-5fcefafa34e0", - "description": "id of deck", - "name": "id", - "in": "path", - "required": true - }, - { - "type": "integer", - "example": 5, - "description": "number of cards", - "name": "num", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.Cards" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/decks/{id}/shuffle": { - "post": { - "description": "shuffle a deck of cards given an id", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "shuffle a deck of cards", - "parameters": [ - { - "type": "string", - "example": "9302b603-13bb-5275-a3b9-5fcefafa34e0", - "description": "id of deck", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.Success" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/version": { - "get": { - "description": "checks the server's version", - "produces": [ - "application/json" - ], - "tags": [ - "core" - ], - "summary": "Version", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/build.Info" - } - } - } - } - } - }, - "definitions": { - "build.Info": { - "type": "object", - "properties": { - "dirty_build": { - "type": "boolean" - }, - "go_version": { - "type": "string" - }, - "last_commit": { - "type": "string" - }, - "revision": { - "type": "string" - } - } - }, - "http.Card": { - "description": "represents a card", - "type": "object", - "properties": { - "code": { - "type": "string", - "example": "AS" - }, - "suit": { - "type": "string", - "example": "SPADES" - }, - "value": { - "type": "string", - "example": "ACE" - } - } - }, - "http.Cards": { - "description": "represents a collection of cards", - "type": "object", - "properties": { - "cards": { - "type": "array", - "items": { - "$ref": "#/definitions/http.Card" - } - } - } - }, - "http.DeckClosed": { - "description": "represents a closed deck of cards", - "type": "object", - "properties": { - "deck_id": { - "type": "string", - "example": "f6afe993-9847-508e-b206-2487f1ef5a3c" - }, - "remaining": { - "type": "integer", - "example": 1 - }, - "shuffled": { - "type": "boolean", - "example": true - } - } - }, - "http.DeckOpened": { - "description": "represents a opened deck of cards", - "type": "object", - "properties": { - "cards": { - "type": "array", - "items": { - "$ref": "#/definitions/http.Card" - } - }, - "deck_id": { - "type": "string", - "example": "f6afe993-9847-508e-b206-2487f1ef5a3c" - }, - "remaining": { - "type": "integer", - "example": 1 - }, - "shuffled": { - "type": "boolean", - "example": true - } - } - }, - "http.Error": { - "description": "defines the structure for a failed response", - "type": "object", - "properties": { - "error": { - "type": "string" - } - } - }, - "http.Success": { - "description": "defines the structure for a successful response", - "type": "object", - "properties": { - "message": { - "type": "string" - } - } - } - } -}` - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = &swag.Spec{ - Version: "v0.3.2", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "Deckr", - Description: "A REST/gRPC API for playing with a deck of cards.", - InfoInstanceName: "swagger", - SwaggerTemplate: docTemplate, -} - -func init() { - swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) -} diff --git a/docs/swagger.json b/docs/swagger.json deleted file mode 100644 index a10ab9d..0000000 --- a/docs/swagger.json +++ /dev/null @@ -1,374 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "A REST/gRPC API for playing with a deck of cards.", - "title": "Deckr", - "contact": { - "name": "Michaël Giovanni Jules", - "url": "https://mgjules.dev", - "email": "julesmichaelgiovanni@gmail.com" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "version": "v0.3.2" - }, - "paths": { - "/": { - "get": { - "description": "checks if server is running", - "produces": [ - "application/json" - ], - "tags": [ - "core" - ], - "summary": "Health Check", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - } - } - } - }, - "/decks": { - "post": { - "description": "creates a new full or partial deck of cards given an optional list of codes", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "creates a new deck of cards", - "parameters": [ - { - "type": "array", - "items": { - "type": "string" - }, - "example": "AS, 2C, 3D, 4H, 5S", - "description": "list of codes", - "name": "codes", - "in": "query" - }, - { - "type": "array", - "items": { - "type": "string" - }, - "example": "french, uno", - "description": "composition of deck", - "name": "comp", - "in": "query" - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/http.DeckClosed" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/decks/{id}": { - "get": { - "description": "opens a deck of cards given an id", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "opens a deck of cards", - "parameters": [ - { - "type": "string", - "example": "9302b603-13bb-5275-a3b9-5fcefafa34e0", - "description": "id of deck", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.DeckOpened" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/decks/{id}/draw": { - "patch": { - "description": "draws cards from a deck of cards given an id and the number of cards", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "draws cards from a deck of cards", - "parameters": [ - { - "type": "string", - "example": "9302b603-13bb-5275-a3b9-5fcefafa34e0", - "description": "id of deck", - "name": "id", - "in": "path", - "required": true - }, - { - "type": "integer", - "example": 5, - "description": "number of cards", - "name": "num", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.Cards" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/decks/{id}/shuffle": { - "post": { - "description": "shuffle a deck of cards given an id", - "produces": [ - "application/json" - ], - "tags": [ - "deck" - ], - "summary": "shuffle a deck of cards", - "parameters": [ - { - "type": "string", - "example": "9302b603-13bb-5275-a3b9-5fcefafa34e0", - "description": "id of deck", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.Success" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/http.Error" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/http.Error" - } - } - } - } - }, - "/version": { - "get": { - "description": "checks the server's version", - "produces": [ - "application/json" - ], - "tags": [ - "core" - ], - "summary": "Version", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/build.Info" - } - } - } - } - } - }, - "definitions": { - "build.Info": { - "type": "object", - "properties": { - "dirty_build": { - "type": "boolean" - }, - "go_version": { - "type": "string" - }, - "last_commit": { - "type": "string" - }, - "revision": { - "type": "string" - } - } - }, - "http.Card": { - "description": "represents a card", - "type": "object", - "properties": { - "code": { - "type": "string", - "example": "AS" - }, - "suit": { - "type": "string", - "example": "SPADES" - }, - "value": { - "type": "string", - "example": "ACE" - } - } - }, - "http.Cards": { - "description": "represents a collection of cards", - "type": "object", - "properties": { - "cards": { - "type": "array", - "items": { - "$ref": "#/definitions/http.Card" - } - } - } - }, - "http.DeckClosed": { - "description": "represents a closed deck of cards", - "type": "object", - "properties": { - "deck_id": { - "type": "string", - "example": "f6afe993-9847-508e-b206-2487f1ef5a3c" - }, - "remaining": { - "type": "integer", - "example": 1 - }, - "shuffled": { - "type": "boolean", - "example": true - } - } - }, - "http.DeckOpened": { - "description": "represents a opened deck of cards", - "type": "object", - "properties": { - "cards": { - "type": "array", - "items": { - "$ref": "#/definitions/http.Card" - } - }, - "deck_id": { - "type": "string", - "example": "f6afe993-9847-508e-b206-2487f1ef5a3c" - }, - "remaining": { - "type": "integer", - "example": 1 - }, - "shuffled": { - "type": "boolean", - "example": true - } - } - }, - "http.Error": { - "description": "defines the structure for a failed response", - "type": "object", - "properties": { - "error": { - "type": "string" - } - } - }, - "http.Success": { - "description": "defines the structure for a successful response", - "type": "object", - "properties": { - "message": { - "type": "string" - } - } - } - } -} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml deleted file mode 100644 index df7dd2b..0000000 --- a/docs/swagger.yaml +++ /dev/null @@ -1,254 +0,0 @@ -definitions: - build.Info: - properties: - dirty_build: - type: boolean - go_version: - type: string - last_commit: - type: string - revision: - type: string - type: object - http.Card: - description: represents a card - properties: - code: - example: AS - type: string - suit: - example: SPADES - type: string - value: - example: ACE - type: string - type: object - http.Cards: - description: represents a collection of cards - properties: - cards: - items: - $ref: '#/definitions/http.Card' - type: array - type: object - http.DeckClosed: - description: represents a closed deck of cards - properties: - deck_id: - example: f6afe993-9847-508e-b206-2487f1ef5a3c - type: string - remaining: - example: 1 - type: integer - shuffled: - example: true - type: boolean - type: object - http.DeckOpened: - description: represents a opened deck of cards - properties: - cards: - items: - $ref: '#/definitions/http.Card' - type: array - deck_id: - example: f6afe993-9847-508e-b206-2487f1ef5a3c - type: string - remaining: - example: 1 - type: integer - shuffled: - example: true - type: boolean - type: object - http.Error: - description: defines the structure for a failed response - properties: - error: - type: string - type: object - http.Success: - description: defines the structure for a successful response - properties: - message: - type: string - type: object -info: - contact: - email: julesmichaelgiovanni@gmail.com - name: Michaël Giovanni Jules - url: https://mgjules.dev - description: A REST/gRPC API for playing with a deck of cards. - license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - title: Deckr - version: v0.3.2 -paths: - /: - get: - description: checks if server is running - produces: - - application/json - responses: - "200": - description: OK - schema: - type: string - summary: Health Check - tags: - - core - /decks: - post: - description: creates a new full or partial deck of cards given an optional list - of codes - parameters: - - description: list of codes - example: AS, 2C, 3D, 4H, 5S - in: query - items: - type: string - name: codes - type: array - - description: composition of deck - example: french, uno - in: query - items: - type: string - name: comp - type: array - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/http.DeckClosed' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.Error' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/http.Error' - summary: creates a new deck of cards - tags: - - deck - /decks/{id}: - get: - description: opens a deck of cards given an id - parameters: - - description: id of deck - example: 9302b603-13bb-5275-a3b9-5fcefafa34e0 - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/http.DeckOpened' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.Error' - "404": - description: Not Found - schema: - $ref: '#/definitions/http.Error' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/http.Error' - summary: opens a deck of cards - tags: - - deck - /decks/{id}/draw: - patch: - description: draws cards from a deck of cards given an id and the number of - cards - parameters: - - description: id of deck - example: 9302b603-13bb-5275-a3b9-5fcefafa34e0 - in: path - name: id - required: true - type: string - - description: number of cards - example: 5 - in: query - name: num - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/http.Cards' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.Error' - "404": - description: Not Found - schema: - $ref: '#/definitions/http.Error' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/http.Error' - summary: draws cards from a deck of cards - tags: - - deck - /decks/{id}/shuffle: - post: - description: shuffle a deck of cards given an id - parameters: - - description: id of deck - example: 9302b603-13bb-5275-a3b9-5fcefafa34e0 - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/http.Success' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.Error' - "404": - description: Not Found - schema: - $ref: '#/definitions/http.Error' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/http.Error' - summary: shuffle a deck of cards - tags: - - deck - /version: - get: - description: checks the server's version - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/build.Info' - summary: Version - tags: - - core -swagger: "2.0" diff --git a/go.mod b/go.mod index 9184060..1841267 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( github.com/gin-contrib/zap v0.0.2 github.com/gin-gonic/gin v1.7.7 + github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 github.com/imdario/mergo v0.3.12 github.com/json-iterator/go v1.1.12 github.com/lib/pq v1.10.4 @@ -13,10 +14,12 @@ require ( github.com/onsi/gomega v1.19.0 github.com/satori/uuid v1.2.0 github.com/swaggo/gin-swagger v1.4.3 - github.com/swaggo/swag v1.8.1 github.com/urfave/cli/v2 v2.6.0 go.uber.org/zap v1.21.0 + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd google.golang.org/grpc v1.46.2 + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 google.golang.org/protobuf v1.28.0 gorm.io/driver/postgres v1.3.5 gorm.io/gorm v1.23.5 @@ -36,8 +39,8 @@ require ( github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.9.0 // indirect + github.com/golang/glog v1.0.0 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/google/go-cmp v0.5.7 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect github.com/jackc/pgconn v1.12.1 // indirect github.com/jackc/pgio v1.0.0 // indirect @@ -57,6 +60,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/stretchr/testify v1.7.1 // indirect + github.com/swaggo/swag v1.8.1 // indirect github.com/ugorji/go/codec v1.2.6 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect @@ -65,6 +69,6 @@ require ( golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.10 // indirect - google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a2020ea..cd4c4b4 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= 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/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -101,13 +103,14 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= @@ -345,6 +348,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -379,6 +383,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -411,16 +416,20 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I= +google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -450,8 +459,9 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/postgres v1.3.5 h1:oVLmefGqBTlgeEVG6LKnH6krOlo4TZ3Q/jIK21KUMlw= gorm.io/driver/postgres v1.3.5/go.mod h1:EGCWefLFQSVFrHGy4J8EtiHCWX5Q8t0yz2Jt9aKkGzU= gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= diff --git a/magefile.go b/magefile.go index 67b887b..0c426ab 100644 --- a/magefile.go +++ b/magefile.go @@ -41,11 +41,6 @@ func Tidy() error { return sh.Run("go", "mod", "tidy") } -// Generates docs -func Docs() error { - return sh.Run("swag", "init", "--parseDependency", "--parseInternal") -} - // Run golangci linters func Lint() error { return sh.Run("golangci-lint", "run", "./...", "--fast") diff --git a/main.go b/main.go index a7b28ea..a06a5dc 100644 --- a/main.go +++ b/main.go @@ -8,17 +8,6 @@ import ( "github.com/urfave/cli/v2" ) -// @title Deckr -// @version v0.3.2 -// @description A REST/gRPC API for playing with a deck of cards. - -// @contact.name Michaël Giovanni Jules -// @contact.url https://mgjules.dev -// @contact.email julesmichaelgiovanni@gmail.com - -// @license.name Apache 2.0 -// @license.url http://www.apache.org/licenses/LICENSE-2.0.html - func main() { app := cli.NewApp() app.Name = "deckr" diff --git a/repo/inmemory/inmemory.go b/repo/inmemory/inmemory.go index c6664cb..d83ab9e 100644 --- a/repo/inmemory/inmemory.go +++ b/repo/inmemory/inmemory.go @@ -41,7 +41,7 @@ func (r *Repository) Get(_ context.Context, id string) (*deck.Deck, error) { return nil, fmt.Errorf("deck '%s': %w", id, err) } - r.log.Debugf("get deck '%s'", d.ID) + r.log.Debugf("get deck '%s'", d.ID()) return d, nil } diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 0000000..709bd37 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,11 @@ +//go:build tools +// +build tools + +package tools + +import ( + _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway" + _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2" + _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" + _ "google.golang.org/protobuf/cmd/protoc-gen-go" +) diff --git a/transport/grpc/deck_service.go b/transport/deck_service.go similarity index 79% rename from transport/grpc/deck_service.go rename to transport/deck_service.go index ff79fcd..8a866d1 100644 --- a/transport/grpc/deck_service.go +++ b/transport/deck_service.go @@ -1,4 +1,4 @@ -package grpc +package transport import ( context "context" @@ -10,6 +10,7 @@ import ( "github.com/mgjules/deckr/logger" "github.com/mgjules/deckr/repo" "github.com/mgjules/deckr/repo/errs" + v1 "github.com/mgjules/deckr/transport/v1" "github.com/satori/uuid" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -19,7 +20,7 @@ import ( type DeckService struct { log *logger.Logger repo repo.Repository - UnimplementedDeckServiceServer + v1.UnimplementedDeckServiceServer } // NewDeckService creates a new DeckService. @@ -32,8 +33,16 @@ func NewDeckService(log *logger.Logger, repo repo.Repository) *DeckService { // CreateDeck creates a new full or partial deck of cards given an optional // list of codes. -func (s *DeckService) CreateDeck(ctx context.Context, req *CreateDeckRequest) (*CreateDeckResponse, error) { - d, err := deck.New(deck.WithComposition(*req.Comp), deck.WithCodes(req.Codes...)) +func (s *DeckService) CreateDeck( + ctx context.Context, + req *v1.CreateDeckRequest, +) (*v1.CreateDeckResponse, error) { + var comp string + if req.Comp != nil { + comp = *req.Comp + } + + d, err := deck.New(deck.WithComposition(comp), deck.WithCodes(req.Codes...)) if err != nil { s.log.Errorf("new deck: %v", err) @@ -55,13 +64,13 @@ func (s *DeckService) CreateDeck(ctx context.Context, req *CreateDeckRequest) (* dc := DomainDeckToDeckClosed(d) - return &CreateDeckResponse{ + return &v1.CreateDeckResponse{ Deck: dc, }, nil } // OpenDeck opens a deck of cards given an id. -func (s *DeckService) OpenDeck(ctx context.Context, req *OpenDeckRequest) (*OpenDeckResponse, error) { +func (s *DeckService) OpenDeck(ctx context.Context, req *v1.OpenDeckRequest) (*v1.OpenDeckResponse, error) { id := req.Id if _, err := uuid.FromString(id); err != nil { s.log.Errorf("parse id: %v", err) @@ -82,14 +91,14 @@ func (s *DeckService) OpenDeck(ctx context.Context, req *OpenDeckRequest) (*Open do := DomainDeckToDeckOpened(d) - return &OpenDeckResponse{ + return &v1.OpenDeckResponse{ Deck: do, }, nil } // DrawCards draws cards from a deck of cards given an id and the number of // cards. -func (s *DeckService) DrawCards(ctx context.Context, req *DrawCardsRequest) (*DrawCardsResponse, error) { +func (s *DeckService) DrawCards(ctx context.Context, req *v1.DrawCardsRequest) (*v1.DrawCardsResponse, error) { id := req.Id if _, err := uuid.FromString(id); err != nil { s.log.Errorf("parse id: %v", err) @@ -134,13 +143,16 @@ func (s *DeckService) DrawCards(ctx context.Context, req *DrawCardsRequest) (*Dr cards := DomainCardsToCards(drawn) - return &DrawCardsResponse{ + return &v1.DrawCardsResponse{ Cards: cards, }, nil } // ShuffleDeck shuffles a deck of cards given an id. -func (s *DeckService) ShuffleDeck(ctx context.Context, req *ShuffleDeckRequest) (*ShuffleDeckResponse, error) { +func (s *DeckService) ShuffleDeck( + ctx context.Context, + req *v1.ShuffleDeckRequest, +) (*v1.ShuffleDeckResponse, error) { id := req.Id if _, err := uuid.FromString(id); err != nil { s.log.Errorf("parse id: %v", err) @@ -167,14 +179,14 @@ func (s *DeckService) ShuffleDeck(ctx context.Context, req *ShuffleDeckRequest) return nil, status.Errorf(codes.Internal, err.Error()) } - return &ShuffleDeckResponse{ + return &v1.ShuffleDeckResponse{ Message: "deck shuffled", }, nil } // DomainDeckToDeckClosed transforms a domain deck to a DeckClosed. -func DomainDeckToDeckClosed(d *deck.Deck) *DeckClosed { - var dc DeckClosed +func DomainDeckToDeckClosed(d *deck.Deck) *v1.DeckClosed { + var dc v1.DeckClosed dc.Id = d.ID() dc.Shuffled = d.IsShuffled() dc.Remaining = uint32(d.Remaining()) @@ -183,8 +195,8 @@ func DomainDeckToDeckClosed(d *deck.Deck) *DeckClosed { } // DomainDeckToDeckOpened transforms a domain deck to a DeckOpened. -func DomainDeckToDeckOpened(d *deck.Deck) *DeckOpened { - var do DeckOpened +func DomainDeckToDeckOpened(d *deck.Deck) *v1.DeckOpened { + var do v1.DeckOpened do.Id = d.ID() do.Shuffled = d.IsShuffled() do.Remaining = uint32(d.Remaining()) @@ -194,10 +206,10 @@ func DomainDeckToDeckOpened(d *deck.Deck) *DeckOpened { } // DomainCardsToCards transforms domain cards to Cards. -func DomainCardsToCards(dc []card.Card) []*Card { - var cc []*Card +func DomainCardsToCards(dc []card.Card) []*v1.Card { + var cc []*v1.Card for _, card := range dc { - cc = append(cc, &Card{ + cc = append(cc, &v1.Card{ Value: card.Rank().String(), Suit: card.Suit().String(), Code: card.Code().String(), diff --git a/transport/grpc/deck_service.pb.go b/transport/grpc/deck_service.pb.go deleted file mode 100644 index 3e69548..0000000 --- a/transport/grpc/deck_service.pb.go +++ /dev/null @@ -1,648 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc (unknown) -// source: transport/grpc/deck_service.proto - -package grpc - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// CreateDeckRequest holds the composition and optional codes needed to create a deck. -type CreateDeckRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Comp *string `protobuf:"bytes,1,opt,name=comp,proto3,oneof" json:"comp,omitempty"` - Codes []string `protobuf:"bytes,2,rep,name=codes,proto3" json:"codes,omitempty"` -} - -func (x *CreateDeckRequest) Reset() { - *x = CreateDeckRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateDeckRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateDeckRequest) ProtoMessage() {} - -func (x *CreateDeckRequest) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateDeckRequest.ProtoReflect.Descriptor instead. -func (*CreateDeckRequest) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{0} -} - -func (x *CreateDeckRequest) GetComp() string { - if x != nil && x.Comp != nil { - return *x.Comp - } - return "" -} - -func (x *CreateDeckRequest) GetCodes() []string { - if x != nil { - return x.Codes - } - return nil -} - -// CreateDeckResponse holds the deck created. -type CreateDeckResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Deck *DeckClosed `protobuf:"bytes,1,opt,name=deck,proto3" json:"deck,omitempty"` -} - -func (x *CreateDeckResponse) Reset() { - *x = CreateDeckResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateDeckResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateDeckResponse) ProtoMessage() {} - -func (x *CreateDeckResponse) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateDeckResponse.ProtoReflect.Descriptor instead. -func (*CreateDeckResponse) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{1} -} - -func (x *CreateDeckResponse) GetDeck() *DeckClosed { - if x != nil { - return x.Deck - } - return nil -} - -// OpenDeckRequest holds the deck id needed to open a deck. -type OpenDeckRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *OpenDeckRequest) Reset() { - *x = OpenDeckRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *OpenDeckRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*OpenDeckRequest) ProtoMessage() {} - -func (x *OpenDeckRequest) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use OpenDeckRequest.ProtoReflect.Descriptor instead. -func (*OpenDeckRequest) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{2} -} - -func (x *OpenDeckRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -// OpenDeckResponse holds the deck opened. -type OpenDeckResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Deck *DeckOpened `protobuf:"bytes,1,opt,name=deck,proto3" json:"deck,omitempty"` -} - -func (x *OpenDeckResponse) Reset() { - *x = OpenDeckResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *OpenDeckResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*OpenDeckResponse) ProtoMessage() {} - -func (x *OpenDeckResponse) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use OpenDeckResponse.ProtoReflect.Descriptor instead. -func (*OpenDeckResponse) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{3} -} - -func (x *OpenDeckResponse) GetDeck() *DeckOpened { - if x != nil { - return x.Deck - } - return nil -} - -// DrawCardsRequest holds the id of the deck and number of cards to draw from the deck. -type DrawCardsRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Num int32 `protobuf:"varint,2,opt,name=num,proto3" json:"num,omitempty"` -} - -func (x *DrawCardsRequest) Reset() { - *x = DrawCardsRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DrawCardsRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DrawCardsRequest) ProtoMessage() {} - -func (x *DrawCardsRequest) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DrawCardsRequest.ProtoReflect.Descriptor instead. -func (*DrawCardsRequest) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{4} -} - -func (x *DrawCardsRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *DrawCardsRequest) GetNum() int32 { - if x != nil { - return x.Num - } - return 0 -} - -// DrawCardsResponse holds the cards drawn. -type DrawCardsResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Cards []*Card `protobuf:"bytes,1,rep,name=cards,proto3" json:"cards,omitempty"` -} - -func (x *DrawCardsResponse) Reset() { - *x = DrawCardsResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DrawCardsResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DrawCardsResponse) ProtoMessage() {} - -func (x *DrawCardsResponse) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DrawCardsResponse.ProtoReflect.Descriptor instead. -func (*DrawCardsResponse) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{5} -} - -func (x *DrawCardsResponse) GetCards() []*Card { - if x != nil { - return x.Cards - } - return nil -} - -// ShuffleDeckRequest holds the id of the deck to shuffle. -type ShuffleDeckRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *ShuffleDeckRequest) Reset() { - *x = ShuffleDeckRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ShuffleDeckRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ShuffleDeckRequest) ProtoMessage() {} - -func (x *ShuffleDeckRequest) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ShuffleDeckRequest.ProtoReflect.Descriptor instead. -func (*ShuffleDeckRequest) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{6} -} - -func (x *ShuffleDeckRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -// ShuffleDeckResponse holds the message after shuffling a deck. -type ShuffleDeckResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` -} - -func (x *ShuffleDeckResponse) Reset() { - *x = ShuffleDeckResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_service_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ShuffleDeckResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ShuffleDeckResponse) ProtoMessage() {} - -func (x *ShuffleDeckResponse) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_service_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ShuffleDeckResponse.ProtoReflect.Descriptor instead. -func (*ShuffleDeckResponse) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_service_proto_rawDescGZIP(), []int{7} -} - -func (x *ShuffleDeckResponse) GetMessage() string { - if x != nil { - return x.Message - } - return "" -} - -var File_transport_grpc_deck_service_proto protoreflect.FileDescriptor - -var file_transport_grpc_deck_service_proto_rawDesc = []byte{ - 0x0a, 0x21, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, - 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x1a, 0x19, 0x74, 0x72, 0x61, 0x6e, 0x73, - 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4b, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, - 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x6f, 0x6d, - 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x63, 0x6f, 0x6d, 0x70, 0x88, - 0x01, 0x01, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x6f, 0x6d, - 0x70, 0x22, 0x3a, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x63, - 0x6b, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x52, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x22, 0x21, 0x0a, - 0x0f, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, - 0x22, 0x38, 0x0a, 0x10, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x63, 0x6b, 0x4f, 0x70, - 0x65, 0x6e, 0x65, 0x64, 0x52, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x22, 0x34, 0x0a, 0x10, 0x44, 0x72, - 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, - 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, - 0x0a, 0x03, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6e, 0x75, 0x6d, - 0x22, 0x35, 0x0a, 0x11, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x05, 0x63, 0x61, 0x72, 0x64, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x61, 0x72, 0x64, - 0x52, 0x05, 0x63, 0x61, 0x72, 0x64, 0x73, 0x22, 0x24, 0x0a, 0x12, 0x53, 0x68, 0x75, 0x66, 0x66, - 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2f, 0x0a, - 0x13, 0x53, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x93, - 0x02, 0x0a, 0x0b, 0x44, 0x65, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x41, - 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x12, 0x17, 0x2e, 0x67, - 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x12, 0x3b, 0x0a, 0x08, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x12, 0x15, 0x2e, - 0x67, 0x72, 0x70, 0x63, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x4f, 0x70, 0x65, 0x6e, - 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3e, - 0x0a, 0x09, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x72, - 0x70, 0x63, 0x2e, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x72, 0x61, 0x77, 0x43, - 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, - 0x0a, 0x0b, 0x53, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x12, 0x18, 0x2e, - 0x67, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x53, - 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x00, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x6d, 0x67, 0x6a, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x72, - 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_transport_grpc_deck_service_proto_rawDescOnce sync.Once - file_transport_grpc_deck_service_proto_rawDescData = file_transport_grpc_deck_service_proto_rawDesc -) - -func file_transport_grpc_deck_service_proto_rawDescGZIP() []byte { - file_transport_grpc_deck_service_proto_rawDescOnce.Do(func() { - file_transport_grpc_deck_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_grpc_deck_service_proto_rawDescData) - }) - return file_transport_grpc_deck_service_proto_rawDescData -} - -var file_transport_grpc_deck_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) -var file_transport_grpc_deck_service_proto_goTypes = []interface{}{ - (*CreateDeckRequest)(nil), // 0: grpc.CreateDeckRequest - (*CreateDeckResponse)(nil), // 1: grpc.CreateDeckResponse - (*OpenDeckRequest)(nil), // 2: grpc.OpenDeckRequest - (*OpenDeckResponse)(nil), // 3: grpc.OpenDeckResponse - (*DrawCardsRequest)(nil), // 4: grpc.DrawCardsRequest - (*DrawCardsResponse)(nil), // 5: grpc.DrawCardsResponse - (*ShuffleDeckRequest)(nil), // 6: grpc.ShuffleDeckRequest - (*ShuffleDeckResponse)(nil), // 7: grpc.ShuffleDeckResponse - (*DeckClosed)(nil), // 8: grpc.DeckClosed - (*DeckOpened)(nil), // 9: grpc.DeckOpened - (*Card)(nil), // 10: grpc.Card -} -var file_transport_grpc_deck_service_proto_depIdxs = []int32{ - 8, // 0: grpc.CreateDeckResponse.deck:type_name -> grpc.DeckClosed - 9, // 1: grpc.OpenDeckResponse.deck:type_name -> grpc.DeckOpened - 10, // 2: grpc.DrawCardsResponse.cards:type_name -> grpc.Card - 0, // 3: grpc.DeckService.CreateDeck:input_type -> grpc.CreateDeckRequest - 2, // 4: grpc.DeckService.OpenDeck:input_type -> grpc.OpenDeckRequest - 4, // 5: grpc.DeckService.DrawCards:input_type -> grpc.DrawCardsRequest - 6, // 6: grpc.DeckService.ShuffleDeck:input_type -> grpc.ShuffleDeckRequest - 1, // 7: grpc.DeckService.CreateDeck:output_type -> grpc.CreateDeckResponse - 3, // 8: grpc.DeckService.OpenDeck:output_type -> grpc.OpenDeckResponse - 5, // 9: grpc.DeckService.DrawCards:output_type -> grpc.DrawCardsResponse - 7, // 10: grpc.DeckService.ShuffleDeck:output_type -> grpc.ShuffleDeckResponse - 7, // [7:11] is the sub-list for method output_type - 3, // [3:7] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name -} - -func init() { file_transport_grpc_deck_service_proto_init() } -func file_transport_grpc_deck_service_proto_init() { - if File_transport_grpc_deck_service_proto != nil { - return - } - file_transport_grpc_deck_proto_init() - if !protoimpl.UnsafeEnabled { - file_transport_grpc_deck_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateDeckRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateDeckResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*OpenDeckRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*OpenDeckResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DrawCardsRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DrawCardsResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ShuffleDeckRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_transport_grpc_deck_service_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ShuffleDeckResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - file_transport_grpc_deck_service_proto_msgTypes[0].OneofWrappers = []interface{}{} - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_transport_grpc_deck_service_proto_rawDesc, - NumEnums: 0, - NumMessages: 8, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_transport_grpc_deck_service_proto_goTypes, - DependencyIndexes: file_transport_grpc_deck_service_proto_depIdxs, - MessageInfos: file_transport_grpc_deck_service_proto_msgTypes, - }.Build() - File_transport_grpc_deck_service_proto = out.File - file_transport_grpc_deck_service_proto_rawDesc = nil - file_transport_grpc_deck_service_proto_goTypes = nil - file_transport_grpc_deck_service_proto_depIdxs = nil -} diff --git a/transport/grpc/deck_service.proto b/transport/grpc/deck_service.proto deleted file mode 100644 index 15ac84c..0000000 --- a/transport/grpc/deck_service.proto +++ /dev/null @@ -1,59 +0,0 @@ -syntax = "proto3"; - -package grpc; - -option go_package = "github.com/mgjules/deckr/grpc;grpc"; - -import "transport/grpc/deck.proto"; - -// CreateDeckRequest holds the composition and optional codes needed to create a deck. -message CreateDeckRequest { - optional string comp = 1; - repeated string codes = 2; -} - -// CreateDeckResponse holds the deck created. -message CreateDeckResponse { - DeckClosed deck = 1; -} - -// OpenDeckRequest holds the deck id needed to open a deck. -message OpenDeckRequest { string id = 1; } - -// OpenDeckResponse holds the deck opened. -message OpenDeckResponse { - DeckOpened deck = 1; -} - -// DrawCardsRequest holds the id of the deck and number of cards to draw from the deck. -message DrawCardsRequest { - string id = 1; - int32 num = 2; -} - -// DrawCardsResponse holds the cards drawn. -message DrawCardsResponse { - repeated Card cards = 1; -} - -// ShuffleDeckRequest holds the id of the deck to shuffle. -message ShuffleDeckRequest { string id = 1; } - -// ShuffleDeckResponse holds the message after shuffling a deck. -message ShuffleDeckResponse { string message = 1; } - -service DeckService { - // CreateDeck creates a new full or partial deck of cards given an optional - // list of codes. - rpc CreateDeck(CreateDeckRequest) returns (CreateDeckResponse) {} - - // OpenDeck opens a deck of cards given an id. - rpc OpenDeck(OpenDeckRequest) returns (OpenDeckResponse) {} - - // DrawCards draws cards from a deck of cards given an id and the number of - // cards. - rpc DrawCards(DrawCardsRequest) returns (DrawCardsResponse) {} - - // ShuffleDeck shuffles a deck of cards given an id. - rpc ShuffleDeck(ShuffleDeckRequest) returns (ShuffleDeckResponse) {} -} \ No newline at end of file diff --git a/transport/grpc/server.go b/transport/grpc_server.go similarity index 62% rename from transport/grpc/server.go rename to transport/grpc_server.go index b8099d9..daf8684 100644 --- a/transport/grpc/server.go +++ b/transport/grpc_server.go @@ -1,4 +1,4 @@ -package grpc +package transport import ( context "context" @@ -7,25 +7,27 @@ import ( "github.com/mgjules/deckr/logger" "github.com/mgjules/deckr/repo" + v1 "github.com/mgjules/deckr/transport/v1" grpc "google.golang.org/grpc" ) -// Server is a grpc server. -type Server struct { +// GRPCServer is a grpc server. +type GRPCServer struct { addr string server *grpc.Server log *logger.Logger repo repo.Repository } -// NewServer creates a new grpc server. -func NewServer( - addr string, +// NewGRPCServer creates a new grpc server. +func NewGRPCServer( + host string, + port int, log *logger.Logger, repo repo.Repository, -) *Server { - s := &Server{ - addr: addr, +) *GRPCServer { + s := &GRPCServer{ + addr: fmt.Sprintf("%s:%d", host, port), server: grpc.NewServer(), log: log, repo: repo, @@ -37,12 +39,12 @@ func NewServer( } // registerServices registers services with the grpc server. -func (s *Server) registerServices() { - RegisterDeckServiceServer(s.server, NewDeckService(s.log, s.repo)) +func (s *GRPCServer) registerServices() { + v1.RegisterDeckServiceServer(s.server, NewDeckService(s.log, s.repo)) } // Start starts the grpc server. -func (s *Server) Start() error { +func (s *GRPCServer) Start() error { s.log.Infof("Listening on tcp://%s...", s.addr) lis, err := net.Listen("tcp", s.addr) @@ -58,7 +60,7 @@ func (s *Server) Start() error { } // Stop stops the grpc server. -func (s *Server) Stop(context.Context) error { +func (s *GRPCServer) Stop(context.Context) error { s.log.Info("Stopping server ...") s.server.GracefulStop() diff --git a/transport/http/card.go b/transport/http/card.go deleted file mode 100644 index 182ee48..0000000 --- a/transport/http/card.go +++ /dev/null @@ -1,31 +0,0 @@ -package http - -import "github.com/mgjules/deckr/card" - -// Card represents a card. -// @Description represents a card -type Card struct { - Value string `json:"value" example:"ACE"` - Suit string `json:"suit" example:"SPADES"` - Code string `json:"code" example:"AS"` -} - -// Cards represents a collection of cards. -// @Description represents a collection of cards -type Cards struct { - Cards []Card `json:"cards"` -} - -// DomainCardsToCards transforms domain cards to Cards. -func DomainCardsToCards(dc []card.Card) *Cards { - var c Cards - for _, card := range dc { - c.Cards = append(c.Cards, Card{ - Value: card.Rank().String(), - Suit: card.Suit().String(), - Code: card.Code().String(), - }) - } - - return &c -} diff --git a/transport/http/deck.go b/transport/http/deck.go deleted file mode 100644 index bc4136c..0000000 --- a/transport/http/deck.go +++ /dev/null @@ -1,39 +0,0 @@ -package http - -import ( - "github.com/mgjules/deckr/deck" -) - -// DeckClosed represents a closed deck of cards. -// @Description represents a closed deck of cards -type DeckClosed struct { - ID string `json:"deck_id" example:"f6afe993-9847-508e-b206-2487f1ef5a3c"` - Shuffled bool `json:"shuffled" example:"true"` - Remaining int `json:"remaining" example:"1"` -} - -// DeckOpened represents a opened deck of cards. -// @Description represents a opened deck of cards -type DeckOpened struct { - DeckClosed - Cards []Card `json:"cards"` -} - -// DomainDeckToDeckClosed transforms a domain deck to a DeckClosed. -func DomainDeckToDeckClosed(d *deck.Deck) *DeckClosed { - var dc DeckClosed - dc.ID = d.ID() - dc.Shuffled = d.IsShuffled() - dc.Remaining = d.Remaining() - - return &dc -} - -// DomainDeckToDeckOpened transforms a domain deck to a DeckOpened. -func DomainDeckToDeckOpened(d *deck.Deck) *DeckOpened { - var do DeckOpened - do.DeckClosed = *DomainDeckToDeckClosed(d) - do.Cards = DomainCardsToCards(d.Cards()).Cards - - return &do -} diff --git a/transport/http/errors.go b/transport/http/errors.go deleted file mode 100644 index 516edbd..0000000 --- a/transport/http/errors.go +++ /dev/null @@ -1,7 +0,0 @@ -package http - -// Error defines the structure for a failed response. -// @Description defines the structure for a failed response -type Error struct { - Error string `json:"error"` -} diff --git a/transport/http/handler.go b/transport/http/handler.go deleted file mode 100644 index 58c2a05..0000000 --- a/transport/http/handler.go +++ /dev/null @@ -1,262 +0,0 @@ -package http - -import ( - "errors" - "net/http" - "strconv" - - "github.com/gin-gonic/gin" - "github.com/mgjules/deckr/card" - "github.com/mgjules/deckr/composition" - "github.com/mgjules/deckr/deck" - "github.com/mgjules/deckr/docs" - "github.com/mgjules/deckr/repo/errs" - "github.com/satori/uuid" - ginSwagger "github.com/swaggo/gin-swagger" - "github.com/swaggo/gin-swagger/swaggerFiles" -) - -// handleHealthCheck godoc -// @Summary Health Check -// @Description checks if server is running -// @Tags core -// @Produce json -// @Success 200 {string} I'm alive! -// @Router / [get] -func (Server) handleHealthCheck() gin.HandlerFunc { - return func(c *gin.Context) { - c.JSON(http.StatusOK, Success{Message: "I'm alive!"}) - } -} - -// handleVersion godoc -// @Summary Version -// @Description checks the server's version -// @Tags core -// @Produce json -// @Success 200 {object} build.Info -// @Router /version [get] -func (s *Server) handleVersion() gin.HandlerFunc { - return func(c *gin.Context) { - c.JSON(http.StatusOK, s.build) - } -} - -func (Server) handleSwagger() gin.HandlerFunc { - docs.SwaggerInfo.BasePath = "/" - - url := ginSwagger.URL("/swagger/doc.json") - - return ginSwagger.WrapHandler(swaggerFiles.Handler, url) -} - -// handleCreateDeck godoc -// @Summary creates a new deck of cards -// @Description creates a new full or partial deck of cards given an optional list of codes -// @Tags deck -// @Produce json -// @Param codes query []string false "list of codes" example(AS, 2C, 3D, 4H, 5S) -// @Param comp query []string false "composition of deck" example(french, uno) -// @Success 201 {object} http.DeckClosed -// @Failure 400 {object} http.Error -// @Failure 500 {object} http.Error -// @Router /decks [post] -func (s *Server) handleCreateDeck() gin.HandlerFunc { - return func(c *gin.Context) { - comp := c.Query("comp") - codes := c.QueryArray("codes") - - d, err := deck.New(deck.WithComposition(comp), deck.WithCodes(codes...)) - if err != nil { - s.log.Errorf("new deck: %v", err) - - if errors.Is(err, composition.ErrUnknownComposition) || - errors.Is(err, card.ErrInvalidCode) || - errors.Is(err, card.ErrInvalidRank) || - errors.Is(err, card.ErrInvalidSuit) { - c.AbortWithStatusJSON(http.StatusBadRequest, Error{err.Error()}) - - return - } - - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - if err := s.repo.Save(c, d); err != nil { - s.log.Errorf("save deck: %v", err) - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - dc := DomainDeckToDeckClosed(d) - - c.JSON(http.StatusCreated, dc) - } -} - -// handleOpenDeck godoc -// @Summary opens a deck of cards -// @Description opens a deck of cards given an id -// @Tags deck -// @Produce json -// @Param id path string true "id of deck" example(9302b603-13bb-5275-a3b9-5fcefafa34e0) -// @Success 200 {object} http.DeckOpened -// @Failure 400 {object} http.Error -// @Failure 404 {object} http.Error -// @Failure 500 {object} http.Error -// @Router /decks/{id} [get] -func (s *Server) handleOpenDeck() gin.HandlerFunc { - return func(c *gin.Context) { - id := c.Param("id") - if _, err := uuid.FromString(id); err != nil { - s.log.Errorf("parse id: %v", err) - c.AbortWithStatusJSON(http.StatusBadRequest, Error{"invalid or missing id"}) - - return - } - - d, err := s.repo.Get(c, id) - if err != nil { - s.log.Errorf("open deck: %v", err) - - if errors.Is(err, errs.ErrDeckNotFound) { - c.AbortWithStatusJSON(http.StatusNotFound, Error{errs.ErrDeckNotFound.Error()}) - - return - } - - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - do := DomainDeckToDeckOpened(d) - - c.JSON(http.StatusOK, do) - } -} - -// handleDrawCards godoc -// @Summary draws cards from a deck of cards -// @Description draws cards from a deck of cards given an id and the number of cards -// @Tags deck -// @Produce json -// @Param id path string true "id of deck" example(9302b603-13bb-5275-a3b9-5fcefafa34e0) -// @Param num query int true "number of cards" example(5) -// @Success 200 {object} http.Cards -// @Failure 400 {object} http.Error -// @Failure 404 {object} http.Error -// @Failure 500 {object} http.Error -// @Router /decks/{id}/draw [patch] -func (s *Server) handleDrawCards() gin.HandlerFunc { - return func(c *gin.Context) { - id := c.Param("id") - if _, err := uuid.FromString(id); err != nil { - s.log.Errorf("parse id: %v", err) - c.AbortWithStatusJSON(http.StatusBadRequest, Error{"invalid or missing id"}) - - return - } - - num, err := strconv.Atoi(c.Query("num")) - if err != nil || num == 0 { - s.log.Errorf("parse num: %v", err) - c.AbortWithStatusJSON(http.StatusBadRequest, Error{"invalid or missing num"}) - - return - } - - d, err := s.repo.Get(c, id) - if err != nil { - s.log.Errorf("get deck: %v", err) - - if errors.Is(err, errs.ErrDeckNotFound) { - c.AbortWithStatusJSON(http.StatusNotFound, Error{errs.ErrDeckNotFound.Error()}) - - return - } - - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - drawn, err := d.Draw(num) - if err != nil { - s.log.Errorf("draw cards: %v", err) - - if errors.Is(err, deck.ErrNotEnoughCards) { - c.AbortWithStatusJSON(http.StatusBadRequest, Error{deck.ErrNotEnoughCards.Error()}) - - return - } - - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - if err := s.repo.Save(c, d); err != nil { - s.log.Errorf("save deck: %v", err) - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - cards := DomainCardsToCards(drawn) - - c.JSON(http.StatusOK, cards) - } -} - -// handleShuffleDeck godoc -// @Summary shuffle a deck of cards -// @Description shuffle a deck of cards given an id -// @Tags deck -// @Produce json -// @Param id path string true "id of deck" example(9302b603-13bb-5275-a3b9-5fcefafa34e0) -// @Success 200 {object} http.Success -// @Failure 400 {object} http.Error -// @Failure 404 {object} http.Error -// @Failure 500 {object} http.Error -// @Router /decks/{id}/shuffle [post] -func (s *Server) handleShuffleDeck() gin.HandlerFunc { - return func(c *gin.Context) { - id := c.Param("id") - if _, err := uuid.FromString(id); err != nil { - s.log.Errorf("parse id: %v", err) - c.AbortWithStatusJSON(http.StatusBadRequest, Error{"invalid or missing id"}) - - return - } - - d, err := s.repo.Get(c, id) - if err != nil { - s.log.Errorf("get deck: %v", err) - - if errors.Is(err, errs.ErrDeckNotFound) { - c.AbortWithStatusJSON(http.StatusNotFound, Error{errs.ErrDeckNotFound.Error()}) - - return - } - - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - d.Shuffle() - - if err := s.repo.Save(c, d); err != nil { - s.log.Errorf("save deck: %v", err) - c.AbortWithStatusJSON(http.StatusInternalServerError, Error{err.Error()}) - - return - } - - c.JSON(http.StatusOK, Success{"deck shuffled"}) - } -} diff --git a/transport/http_handler.go b/transport/http_handler.go new file mode 100644 index 0000000..2fb0109 --- /dev/null +++ b/transport/http_handler.go @@ -0,0 +1,31 @@ +package transport + +import ( + "embed" + "net/http" + + "github.com/gin-gonic/gin" + ginSwagger "github.com/swaggo/gin-swagger" + "github.com/swaggo/gin-swagger/swaggerFiles" +) + +//go:embed v1/deck_service.swagger.json +var docsFS embed.FS + +func (HTTPServer) handleHealthCheck() gin.HandlerFunc { + return func(c *gin.Context) { + c.JSON(http.StatusOK, Success{Message: "I'm alive!"}) + } +} + +func (s *HTTPServer) handleVersion() gin.HandlerFunc { + return func(c *gin.Context) { + c.JSON(http.StatusOK, s.build) + } +} + +func (HTTPServer) handleSwagger() gin.HandlerFunc { + url := ginSwagger.URL("/docs/v1/deck_service.swagger.json") + + return ginSwagger.WrapHandler(swaggerFiles.Handler, url) +} diff --git a/transport/http/server.go b/transport/http_server.go similarity index 56% rename from transport/http/server.go rename to transport/http_server.go index b5adfe4..67f2694 100644 --- a/transport/http/server.go +++ b/transport/http_server.go @@ -1,4 +1,4 @@ -package http +package transport import ( "context" @@ -8,9 +8,12 @@ import ( ginzap "github.com/gin-contrib/zap" "github.com/gin-gonic/gin" + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/mgjules/deckr/build" "github.com/mgjules/deckr/logger" - "github.com/mgjules/deckr/repo" + v1 "github.com/mgjules/deckr/transport/v1" + grpc "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) const ( @@ -20,24 +23,24 @@ const ( _readHeaderTimeout = 2 * time.Second ) -// Server is the main HTTP server. -type Server struct { - router *gin.Engine - http *http.Server - log *logger.Logger - build *build.Info - repo repo.Repository - addr string +// HTTPServer is the main HTTP server. +type HTTPServer struct { + router *gin.Engine + http *http.Server + log *logger.Logger + build *build.Info + addr string + grpcAddr string } -// NewServer creates a new Server. -func NewServer( +// NewHTTPServer creates a new Server. +func NewHTTPServer( debug bool, - addr string, + host string, + port int, logger *logger.Logger, build *build.Info, - repo repo.Repository, -) *Server { +) *HTTPServer { if !debug { gin.SetMode(gin.ReleaseMode) } @@ -46,12 +49,12 @@ func NewServer( gin.DefaultWriter = w gin.DefaultErrorWriter = w - s := Server{ - router: gin.Default(), - addr: addr, - log: logger, - build: build, - repo: repo, + s := HTTPServer{ + router: gin.Default(), + addr: fmt.Sprintf("%s:%d", host, port), + grpcAddr: fmt.Sprintf("%s:%d", host, port-1), + log: logger, + build: build, } desugared := logger.Desugar() @@ -72,7 +75,7 @@ func NewServer( return &s } -func (s *Server) registerRoutes() { +func (s *HTTPServer) registerRoutes() { // Health Check s.router.GET("/", s.handleHealthCheck()) @@ -80,20 +83,26 @@ func (s *Server) registerRoutes() { s.router.GET("/version", s.handleVersion()) // Swagger + s.router.StaticFS("/docs", http.FS(docsFS)) s.router.GET("/swagger/*any", s.handleSwagger()) - deck := s.router.Group("/decks") - { - deck.POST("", s.handleCreateDeck()) - deck.GET("/:id", s.handleOpenDeck()) - deck.PATCH("/:id/draw", s.handleDrawCards()) - deck.POST("/:id/shuffle", s.handleShuffleDeck()) + // Decks + mux := runtime.NewServeMux() + if err := v1.RegisterDeckServiceHandlerFromEndpoint( + context.Background(), + mux, + s.grpcAddr, + []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}, + ); err != nil { + s.log.Errorf("register grpc gateway: %v", err) } + + s.router.Group("/v1/*{grpc_gateway}").Any("", gin.WrapH(mux)) } // Start starts the server. // It blocks until the server stops. -func (s *Server) Start() error { +func (s *HTTPServer) Start() error { s.log.Infof("Listening on http://%s...", s.addr) if err := s.http.ListenAndServe(); err != nil && err != http.ErrServerClosed { @@ -104,7 +113,7 @@ func (s *Server) Start() error { } // Stop stops the server. -func (s *Server) Stop(ctx context.Context) error { +func (s *HTTPServer) Stop(ctx context.Context) error { s.log.Info("Stopping server ...") if err := s.http.Shutdown(ctx); err != nil { diff --git a/transport/http/success.go b/transport/success.go similarity index 91% rename from transport/http/success.go rename to transport/success.go index 1933dd2..276d2e4 100644 --- a/transport/http/success.go +++ b/transport/success.go @@ -1,4 +1,4 @@ -package http +package transport // Success defines the structure for a successful response. // @Description defines the structure for a successful response diff --git a/transport/transport.go b/transport/transport.go deleted file mode 100644 index e012673..0000000 --- a/transport/transport.go +++ /dev/null @@ -1,42 +0,0 @@ -package transport - -import ( - "context" - "fmt" - "net/url" - - "github.com/mgjules/deckr/build" - "github.com/mgjules/deckr/logger" - "github.com/mgjules/deckr/repo" - "github.com/mgjules/deckr/transport/grpc" - "github.com/mgjules/deckr/transport/http" -) - -// Transporter is an interface to perform deck operations. -type Transporter interface { - Start() error - Stop(context.Context) error -} - -// NewTransporter returns a new transporter. -func NewTransporter( - debug bool, - uri string, - log *logger.Logger, - build *build.Info, - repo repo.Repository, -) (Transporter, error) { - u, err := url.Parse(uri) - if err != nil { - return nil, fmt.Errorf("invalid transporter URI: %w", err) - } - - switch u.Scheme { - case "http": - return http.NewServer(debug, u.Host, log, build, repo), nil - case "tcp": - return grpc.NewServer(u.Host, log, repo), nil - default: - return nil, fmt.Errorf("unknown transporter URI scheme: %s", u.Scheme) - } -} diff --git a/transport/grpc/deck.pb.go b/transport/v1/deck.pb.go similarity index 56% rename from transport/grpc/deck.pb.go rename to transport/v1/deck.pb.go index cb1f721..5b21690 100644 --- a/transport/grpc/deck.pb.go +++ b/transport/v1/deck.pb.go @@ -2,9 +2,9 @@ // versions: // protoc-gen-go v1.28.0 // protoc (unknown) -// source: transport/grpc/deck.proto +// source: transport/v1/deck.proto -package grpc +package v1 import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -35,7 +35,7 @@ type DeckOpened struct { func (x *DeckOpened) Reset() { *x = DeckOpened{} if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_proto_msgTypes[0] + mi := &file_transport_v1_deck_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -48,7 +48,7 @@ func (x *DeckOpened) String() string { func (*DeckOpened) ProtoMessage() {} func (x *DeckOpened) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_proto_msgTypes[0] + mi := &file_transport_v1_deck_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -61,7 +61,7 @@ func (x *DeckOpened) ProtoReflect() protoreflect.Message { // Deprecated: Use DeckOpened.ProtoReflect.Descriptor instead. func (*DeckOpened) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_proto_rawDescGZIP(), []int{0} + return file_transport_v1_deck_proto_rawDescGZIP(), []int{0} } func (x *DeckOpened) GetId() string { @@ -106,7 +106,7 @@ type DeckClosed struct { func (x *DeckClosed) Reset() { *x = DeckClosed{} if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_proto_msgTypes[1] + mi := &file_transport_v1_deck_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -119,7 +119,7 @@ func (x *DeckClosed) String() string { func (*DeckClosed) ProtoMessage() {} func (x *DeckClosed) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_proto_msgTypes[1] + mi := &file_transport_v1_deck_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -132,7 +132,7 @@ func (x *DeckClosed) ProtoReflect() protoreflect.Message { // Deprecated: Use DeckClosed.ProtoReflect.Descriptor instead. func (*DeckClosed) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_proto_rawDescGZIP(), []int{1} + return file_transport_v1_deck_proto_rawDescGZIP(), []int{1} } func (x *DeckClosed) GetId() string { @@ -170,7 +170,7 @@ type Card struct { func (x *Card) Reset() { *x = Card{} if protoimpl.UnsafeEnabled { - mi := &file_transport_grpc_deck_proto_msgTypes[2] + mi := &file_transport_v1_deck_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -183,7 +183,7 @@ func (x *Card) String() string { func (*Card) ProtoMessage() {} func (x *Card) ProtoReflect() protoreflect.Message { - mi := &file_transport_grpc_deck_proto_msgTypes[2] + mi := &file_transport_v1_deck_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -196,7 +196,7 @@ func (x *Card) ProtoReflect() protoreflect.Message { // Deprecated: Use Card.ProtoReflect.Descriptor instead. func (*Card) Descriptor() ([]byte, []int) { - return file_transport_grpc_deck_proto_rawDescGZIP(), []int{2} + return file_transport_v1_deck_proto_rawDescGZIP(), []int{2} } func (x *Card) GetValue() string { @@ -220,54 +220,55 @@ func (x *Card) GetCode() string { return "" } -var File_transport_grpc_deck_proto protoreflect.FileDescriptor - -var file_transport_grpc_deck_proto_rawDesc = []byte{ - 0x0a, 0x19, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, - 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x67, 0x72, 0x70, - 0x63, 0x22, 0x78, 0x0a, 0x0a, 0x44, 0x65, 0x63, 0x6b, 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x08, 0x73, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, - 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, - 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x12, 0x20, 0x0a, 0x05, 0x63, 0x61, 0x72, - 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, - 0x43, 0x61, 0x72, 0x64, 0x52, 0x05, 0x63, 0x61, 0x72, 0x64, 0x73, 0x22, 0x56, 0x0a, 0x0a, 0x44, - 0x65, 0x63, 0x6b, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x75, - 0x66, 0x66, 0x6c, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x73, 0x68, 0x75, - 0x66, 0x66, 0x6c, 0x65, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, - 0x6e, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, - 0x69, 0x6e, 0x67, 0x22, 0x44, 0x0a, 0x04, 0x43, 0x61, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x75, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x73, 0x75, 0x69, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x67, 0x6a, 0x75, 0x6c, 0x65, 0x73, 0x2f, - 0x64, 0x65, 0x63, 0x6b, 0x72, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x67, 0x72, 0x70, 0x63, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +var File_transport_v1_deck_proto protoreflect.FileDescriptor + +var file_transport_v1_deck_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x64, + 0x65, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73, + 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x22, 0x80, 0x01, 0x0a, 0x0a, 0x44, 0x65, 0x63, 0x6b, + 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x75, 0x66, 0x66, 0x6c, + 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x73, 0x68, 0x75, 0x66, 0x66, 0x6c, + 0x65, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, + 0x12, 0x28, 0x0a, 0x05, 0x63, 0x61, 0x72, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x12, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x72, 0x64, 0x52, 0x05, 0x63, 0x61, 0x72, 0x64, 0x73, 0x22, 0x56, 0x0a, 0x0a, 0x44, 0x65, + 0x63, 0x6b, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x75, 0x66, + 0x66, 0x6c, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x73, 0x68, 0x75, 0x66, + 0x66, 0x6c, 0x65, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, + 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, + 0x6e, 0x67, 0x22, 0x44, 0x0a, 0x04, 0x43, 0x61, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x73, 0x75, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x73, 0x75, 0x69, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x67, 0x6a, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x64, + 0x65, 0x63, 0x6b, 0x72, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x76, + 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_transport_grpc_deck_proto_rawDescOnce sync.Once - file_transport_grpc_deck_proto_rawDescData = file_transport_grpc_deck_proto_rawDesc + file_transport_v1_deck_proto_rawDescOnce sync.Once + file_transport_v1_deck_proto_rawDescData = file_transport_v1_deck_proto_rawDesc ) -func file_transport_grpc_deck_proto_rawDescGZIP() []byte { - file_transport_grpc_deck_proto_rawDescOnce.Do(func() { - file_transport_grpc_deck_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_grpc_deck_proto_rawDescData) +func file_transport_v1_deck_proto_rawDescGZIP() []byte { + file_transport_v1_deck_proto_rawDescOnce.Do(func() { + file_transport_v1_deck_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_v1_deck_proto_rawDescData) }) - return file_transport_grpc_deck_proto_rawDescData + return file_transport_v1_deck_proto_rawDescData } -var file_transport_grpc_deck_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_transport_grpc_deck_proto_goTypes = []interface{}{ - (*DeckOpened)(nil), // 0: grpc.DeckOpened - (*DeckClosed)(nil), // 1: grpc.DeckClosed - (*Card)(nil), // 2: grpc.Card +var file_transport_v1_deck_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_transport_v1_deck_proto_goTypes = []interface{}{ + (*DeckOpened)(nil), // 0: transport.v1.DeckOpened + (*DeckClosed)(nil), // 1: transport.v1.DeckClosed + (*Card)(nil), // 2: transport.v1.Card } -var file_transport_grpc_deck_proto_depIdxs = []int32{ - 2, // 0: grpc.DeckOpened.cards:type_name -> grpc.Card +var file_transport_v1_deck_proto_depIdxs = []int32{ + 2, // 0: transport.v1.DeckOpened.cards:type_name -> transport.v1.Card 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -275,13 +276,13 @@ var file_transport_grpc_deck_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_transport_grpc_deck_proto_init() } -func file_transport_grpc_deck_proto_init() { - if File_transport_grpc_deck_proto != nil { +func init() { file_transport_v1_deck_proto_init() } +func file_transport_v1_deck_proto_init() { + if File_transport_v1_deck_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_transport_grpc_deck_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_transport_v1_deck_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DeckOpened); i { case 0: return &v.state @@ -293,7 +294,7 @@ func file_transport_grpc_deck_proto_init() { return nil } } - file_transport_grpc_deck_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_transport_v1_deck_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DeckClosed); i { case 0: return &v.state @@ -305,7 +306,7 @@ func file_transport_grpc_deck_proto_init() { return nil } } - file_transport_grpc_deck_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_transport_v1_deck_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Card); i { case 0: return &v.state @@ -322,18 +323,18 @@ func file_transport_grpc_deck_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_transport_grpc_deck_proto_rawDesc, + RawDescriptor: file_transport_v1_deck_proto_rawDesc, NumEnums: 0, NumMessages: 3, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_transport_grpc_deck_proto_goTypes, - DependencyIndexes: file_transport_grpc_deck_proto_depIdxs, - MessageInfos: file_transport_grpc_deck_proto_msgTypes, + GoTypes: file_transport_v1_deck_proto_goTypes, + DependencyIndexes: file_transport_v1_deck_proto_depIdxs, + MessageInfos: file_transport_v1_deck_proto_msgTypes, }.Build() - File_transport_grpc_deck_proto = out.File - file_transport_grpc_deck_proto_rawDesc = nil - file_transport_grpc_deck_proto_goTypes = nil - file_transport_grpc_deck_proto_depIdxs = nil + File_transport_v1_deck_proto = out.File + file_transport_v1_deck_proto_rawDesc = nil + file_transport_v1_deck_proto_goTypes = nil + file_transport_v1_deck_proto_depIdxs = nil } diff --git a/transport/grpc/deck.proto b/transport/v1/deck.proto similarity index 83% rename from transport/grpc/deck.proto rename to transport/v1/deck.proto index 07c5369..6edcf04 100644 --- a/transport/grpc/deck.proto +++ b/transport/v1/deck.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package grpc; +package transport.v1; -option go_package = "github.com/mgjules/deckr/grpc;grpc"; +option go_package = "github.com/mgjules/deckr/transport/v1;v1"; // DeckOpened represents a opened deck of cards. message DeckOpened { diff --git a/transport/v1/deck.swagger.json b/transport/v1/deck.swagger.json new file mode 100644 index 0000000..5f431ee --- /dev/null +++ b/transport/v1/deck.swagger.json @@ -0,0 +1,43 @@ +{ + "swagger": "2.0", + "info": { + "title": "transport/v1/deck.proto", + "version": "version not set" + }, + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": {}, + "definitions": { + "protobufAny": { + "type": "object", + "properties": { + "@type": { + "type": "string" + } + }, + "additionalProperties": {} + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/transport/v1/deck_service.pb.go b/transport/v1/deck_service.pb.go new file mode 100644 index 0000000..580d29a --- /dev/null +++ b/transport/v1/deck_service.pb.go @@ -0,0 +1,751 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc (unknown) +// source: transport/v1/deck_service.proto + +package v1 + +import ( + _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options" + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// CreateDeckRequest holds the composition and optional codes needed to create a deck. +type CreateDeckRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comp *string `protobuf:"bytes,1,opt,name=comp,proto3,oneof" json:"comp,omitempty"` + Codes []string `protobuf:"bytes,2,rep,name=codes,proto3" json:"codes,omitempty"` +} + +func (x *CreateDeckRequest) Reset() { + *x = CreateDeckRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateDeckRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateDeckRequest) ProtoMessage() {} + +func (x *CreateDeckRequest) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateDeckRequest.ProtoReflect.Descriptor instead. +func (*CreateDeckRequest) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{0} +} + +func (x *CreateDeckRequest) GetComp() string { + if x != nil && x.Comp != nil { + return *x.Comp + } + return "" +} + +func (x *CreateDeckRequest) GetCodes() []string { + if x != nil { + return x.Codes + } + return nil +} + +// CreateDeckResponse holds the deck created. +type CreateDeckResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Deck *DeckClosed `protobuf:"bytes,1,opt,name=deck,proto3" json:"deck,omitempty"` +} + +func (x *CreateDeckResponse) Reset() { + *x = CreateDeckResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateDeckResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateDeckResponse) ProtoMessage() {} + +func (x *CreateDeckResponse) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateDeckResponse.ProtoReflect.Descriptor instead. +func (*CreateDeckResponse) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateDeckResponse) GetDeck() *DeckClosed { + if x != nil { + return x.Deck + } + return nil +} + +// OpenDeckRequest holds the deck id needed to open a deck. +type OpenDeckRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *OpenDeckRequest) Reset() { + *x = OpenDeckRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OpenDeckRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpenDeckRequest) ProtoMessage() {} + +func (x *OpenDeckRequest) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OpenDeckRequest.ProtoReflect.Descriptor instead. +func (*OpenDeckRequest) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{2} +} + +func (x *OpenDeckRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +// OpenDeckResponse holds the deck opened. +type OpenDeckResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Deck *DeckOpened `protobuf:"bytes,1,opt,name=deck,proto3" json:"deck,omitempty"` +} + +func (x *OpenDeckResponse) Reset() { + *x = OpenDeckResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OpenDeckResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpenDeckResponse) ProtoMessage() {} + +func (x *OpenDeckResponse) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OpenDeckResponse.ProtoReflect.Descriptor instead. +func (*OpenDeckResponse) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{3} +} + +func (x *OpenDeckResponse) GetDeck() *DeckOpened { + if x != nil { + return x.Deck + } + return nil +} + +// DrawCardsRequest holds the id of the deck and number of cards to draw from the deck. +type DrawCardsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Num int32 `protobuf:"varint,2,opt,name=num,proto3" json:"num,omitempty"` +} + +func (x *DrawCardsRequest) Reset() { + *x = DrawCardsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DrawCardsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DrawCardsRequest) ProtoMessage() {} + +func (x *DrawCardsRequest) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DrawCardsRequest.ProtoReflect.Descriptor instead. +func (*DrawCardsRequest) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{4} +} + +func (x *DrawCardsRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *DrawCardsRequest) GetNum() int32 { + if x != nil { + return x.Num + } + return 0 +} + +// DrawCardsResponse holds the cards drawn. +type DrawCardsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Cards []*Card `protobuf:"bytes,1,rep,name=cards,proto3" json:"cards,omitempty"` +} + +func (x *DrawCardsResponse) Reset() { + *x = DrawCardsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DrawCardsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DrawCardsResponse) ProtoMessage() {} + +func (x *DrawCardsResponse) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DrawCardsResponse.ProtoReflect.Descriptor instead. +func (*DrawCardsResponse) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{5} +} + +func (x *DrawCardsResponse) GetCards() []*Card { + if x != nil { + return x.Cards + } + return nil +} + +// ShuffleDeckRequest holds the id of the deck to shuffle. +type ShuffleDeckRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *ShuffleDeckRequest) Reset() { + *x = ShuffleDeckRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShuffleDeckRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShuffleDeckRequest) ProtoMessage() {} + +func (x *ShuffleDeckRequest) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShuffleDeckRequest.ProtoReflect.Descriptor instead. +func (*ShuffleDeckRequest) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{6} +} + +func (x *ShuffleDeckRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +// ShuffleDeckResponse holds the message after shuffling a deck. +type ShuffleDeckResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *ShuffleDeckResponse) Reset() { + *x = ShuffleDeckResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_transport_v1_deck_service_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShuffleDeckResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShuffleDeckResponse) ProtoMessage() {} + +func (x *ShuffleDeckResponse) ProtoReflect() protoreflect.Message { + mi := &file_transport_v1_deck_service_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShuffleDeckResponse.ProtoReflect.Descriptor instead. +func (*ShuffleDeckResponse) Descriptor() ([]byte, []int) { + return file_transport_v1_deck_service_proto_rawDescGZIP(), []int{7} +} + +func (x *ShuffleDeckResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_transport_v1_deck_service_proto protoreflect.FileDescriptor + +var file_transport_v1_deck_service_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x64, + 0x65, 0x63, 0x6b, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x1a, + 0x17, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, + 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, + 0x65, 0x6e, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x6f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4b, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x04, 0x63, + 0x6f, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x63, 0x6f, 0x6d, + 0x70, 0x88, 0x01, 0x01, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, + 0x6f, 0x6d, 0x70, 0x22, 0x42, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, + 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x04, 0x64, 0x65, 0x63, + 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, + 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x63, 0x6b, 0x43, 0x6c, 0x6f, 0x73, 0x65, + 0x64, 0x52, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x22, 0x21, 0x0a, 0x0f, 0x4f, 0x70, 0x65, 0x6e, 0x44, + 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x40, 0x0a, 0x10, 0x4f, 0x70, + 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, + 0x0a, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x63, 0x6b, + 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x52, 0x04, 0x64, 0x65, 0x63, 0x6b, 0x22, 0x34, 0x0a, 0x10, + 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, + 0x12, 0x10, 0x0a, 0x03, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6e, + 0x75, 0x6d, 0x22, 0x3d, 0x0a, 0x11, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x05, 0x63, 0x61, 0x72, 0x64, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, + 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x72, 0x64, 0x52, 0x05, 0x63, 0x61, 0x72, 0x64, + 0x73, 0x22, 0x24, 0x0a, 0x12, 0x53, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2f, 0x0a, 0x13, 0x53, 0x68, 0x75, 0x66, 0x66, + 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xf4, 0x0b, 0x0a, 0x0b, 0x44, 0x65, 0x63, + 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0xe3, 0x02, 0x0a, 0x0a, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x12, 0x1f, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, + 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, + 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, + 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, + 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x91, 0x02, 0x92, 0x41, 0xfc, + 0x01, 0x12, 0x4c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x73, 0x20, 0x61, 0x20, 0x6e, 0x65, 0x77, + 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, + 0x20, 0x64, 0x65, 0x63, 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, 0x20, 0x67, + 0x69, 0x76, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, + 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2e, 0x2a, + 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x4a, 0x20, 0x0a, 0x03, 0x32, + 0x30, 0x30, 0x12, 0x19, 0x0a, 0x17, 0x41, 0x20, 0x66, 0x72, 0x65, 0x73, 0x68, 0x6c, 0x79, 0x20, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x64, 0x65, 0x63, 0x6b, 0x2e, 0x4a, 0x40, 0x0a, + 0x03, 0x34, 0x30, 0x30, 0x12, 0x39, 0x0a, 0x1a, 0x54, 0x68, 0x65, 0x20, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x20, 0x77, 0x61, 0x73, 0x20, 0x6d, 0x61, 0x6c, 0x66, 0x6f, 0x72, 0x6d, 0x65, + 0x64, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4a, + 0x3c, 0x0a, 0x03, 0x35, 0x30, 0x30, 0x12, 0x35, 0x0a, 0x16, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2e, + 0x12, 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x0b, 0x22, 0x09, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x73, 0x12, 0xdd, + 0x02, 0x0a, 0x08, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x12, 0x1d, 0x2e, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x44, + 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x74, 0x72, 0x61, + 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, + 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x91, 0x02, 0x92, 0x41, 0xf7, + 0x01, 0x12, 0x22, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x20, 0x61, 0x20, 0x64, 0x65, 0x63, 0x6b, 0x20, + 0x6f, 0x66, 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x20, 0x61, + 0x6e, 0x20, 0x69, 0x64, 0x2e, 0x2a, 0x08, 0x4f, 0x70, 0x65, 0x6e, 0x44, 0x65, 0x63, 0x6b, 0x4a, + 0x10, 0x0a, 0x03, 0x32, 0x30, 0x30, 0x12, 0x09, 0x0a, 0x07, 0x41, 0x20, 0x64, 0x65, 0x63, 0x6b, + 0x2e, 0x4a, 0x40, 0x0a, 0x03, 0x34, 0x30, 0x30, 0x12, 0x39, 0x0a, 0x1a, 0x54, 0x68, 0x65, 0x20, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x20, 0x77, 0x61, 0x73, 0x20, 0x6d, 0x61, 0x6c, 0x66, + 0x6f, 0x72, 0x6d, 0x65, 0x64, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, + 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x4a, 0x35, 0x0a, 0x03, 0x34, 0x30, 0x34, 0x12, 0x2e, 0x0a, 0x0f, 0x44, 0x65, + 0x63, 0x6b, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x2e, 0x12, 0x1b, 0x0a, + 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4a, 0x3c, 0x0a, 0x03, 0x35, 0x30, + 0x30, 0x12, 0x35, 0x0a, 0x16, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, + 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, + 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, + 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x98, + 0x03, 0x0a, 0x09, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x12, 0x1e, 0x2e, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x72, 0x61, 0x77, + 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x72, 0x61, 0x77, + 0x43, 0x61, 0x72, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xc9, 0x02, + 0x92, 0x41, 0xa4, 0x02, 0x12, 0x45, 0x64, 0x72, 0x61, 0x77, 0x73, 0x20, 0x63, 0x61, 0x72, 0x64, + 0x73, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x61, 0x20, 0x64, 0x65, 0x63, 0x6b, 0x20, 0x6f, 0x66, + 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x20, + 0x69, 0x64, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, 0x2e, 0x2a, 0x09, 0x44, 0x72, 0x61, + 0x77, 0x43, 0x61, 0x72, 0x64, 0x73, 0x4a, 0x19, 0x0a, 0x03, 0x32, 0x30, 0x30, 0x12, 0x12, 0x0a, + 0x10, 0x41, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, + 0x2e, 0x4a, 0x40, 0x0a, 0x03, 0x34, 0x30, 0x30, 0x12, 0x39, 0x0a, 0x1a, 0x54, 0x68, 0x65, 0x20, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x20, 0x77, 0x61, 0x73, 0x20, 0x6d, 0x61, 0x6c, 0x66, + 0x6f, 0x72, 0x6d, 0x65, 0x64, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, + 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x4a, 0x35, 0x0a, 0x03, 0x34, 0x30, 0x34, 0x12, 0x2e, 0x0a, 0x0f, 0x44, 0x65, + 0x63, 0x6b, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x2e, 0x12, 0x1b, 0x0a, + 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4a, 0x3c, 0x0a, 0x03, 0x35, 0x30, + 0x30, 0x12, 0x35, 0x0a, 0x16, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, + 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, + 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x32, 0x19, + 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x2f, 0x64, + 0x72, 0x61, 0x77, 0x2f, 0x7b, 0x6e, 0x75, 0x6d, 0x7d, 0x12, 0x83, 0x03, 0x0a, 0x0b, 0x53, 0x68, + 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x12, 0x20, 0x2e, 0x74, 0x72, 0x61, 0x6e, + 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, + 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x75, 0x66, 0x66, + 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xae, + 0x02, 0x92, 0x41, 0x8c, 0x02, 0x12, 0x25, 0x73, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x73, 0x20, + 0x61, 0x20, 0x64, 0x65, 0x63, 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, 0x20, + 0x67, 0x69, 0x76, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x69, 0x64, 0x2e, 0x2a, 0x0b, 0x53, 0x68, + 0x75, 0x66, 0x66, 0x6c, 0x65, 0x44, 0x65, 0x63, 0x6b, 0x4a, 0x1f, 0x0a, 0x03, 0x32, 0x30, 0x30, + 0x12, 0x18, 0x0a, 0x16, 0x41, 0x20, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, + 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4a, 0x40, 0x0a, 0x03, 0x34, 0x30, + 0x30, 0x12, 0x39, 0x0a, 0x1a, 0x54, 0x68, 0x65, 0x20, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x20, 0x77, 0x61, 0x73, 0x20, 0x6d, 0x61, 0x6c, 0x66, 0x6f, 0x72, 0x6d, 0x65, 0x64, 0x2e, 0x12, + 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4a, 0x35, 0x0a, 0x03, + 0x34, 0x30, 0x34, 0x12, 0x2e, 0x0a, 0x0f, 0x44, 0x65, 0x63, 0x6b, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, + 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x4a, 0x3c, 0x0a, 0x03, 0x35, 0x30, 0x30, 0x12, 0x35, 0x0a, 0x16, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x2e, 0x12, 0x1b, 0x0a, 0x19, 0x1a, 0x17, 0x23, 0x2f, 0x64, 0x65, 0x66, 0x69, + 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x22, 0x16, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, 0x63, + 0x6b, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x2f, 0x73, 0x68, 0x75, 0x66, 0x66, 0x6c, 0x65, 0x42, + 0xb6, 0x02, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, + 0x67, 0x6a, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x64, 0x65, 0x63, 0x6b, 0x72, 0x2f, 0x74, 0x72, 0x61, + 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x92, 0x41, 0x88, 0x02, + 0x12, 0xde, 0x01, 0x0a, 0x05, 0x44, 0x65, 0x63, 0x6b, 0x72, 0x12, 0x31, 0x41, 0x20, 0x52, 0x45, + 0x53, 0x54, 0x2f, 0x67, 0x52, 0x50, 0x43, 0x20, 0x41, 0x50, 0x49, 0x20, 0x66, 0x6f, 0x72, 0x20, + 0x70, 0x6c, 0x61, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, 0x64, + 0x65, 0x63, 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x61, 0x72, 0x64, 0x73, 0x2e, 0x22, 0x4e, 0x0a, + 0x17, 0x4d, 0x69, 0x63, 0x68, 0x61, 0xc3, 0xab, 0x6c, 0x20, 0x47, 0x69, 0x6f, 0x76, 0x61, 0x6e, + 0x6e, 0x69, 0x20, 0x4a, 0x75, 0x6c, 0x65, 0x73, 0x12, 0x13, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, + 0x2f, 0x2f, 0x6d, 0x67, 0x6a, 0x75, 0x6c, 0x65, 0x73, 0x2e, 0x64, 0x65, 0x76, 0x1a, 0x1e, 0x6a, + 0x75, 0x6c, 0x65, 0x73, 0x6d, 0x69, 0x63, 0x68, 0x61, 0x65, 0x6c, 0x67, 0x69, 0x6f, 0x76, 0x61, + 0x6e, 0x6e, 0x69, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x2a, 0x4a, 0x0a, + 0x12, 0x41, 0x70, 0x61, 0x63, 0x68, 0x65, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x4c, 0x69, 0x63, 0x65, + 0x6e, 0x73, 0x65, 0x12, 0x34, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x67, 0x6a, 0x75, 0x6c, 0x65, 0x73, 0x2f, + 0x64, 0x65, 0x63, 0x6b, 0x72, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x73, 0x74, 0x65, + 0x72, 0x2f, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x32, 0x06, 0x76, 0x30, 0x2e, 0x33, 0x2e, + 0x32, 0x2a, 0x01, 0x01, 0x32, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x3a, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_transport_v1_deck_service_proto_rawDescOnce sync.Once + file_transport_v1_deck_service_proto_rawDescData = file_transport_v1_deck_service_proto_rawDesc +) + +func file_transport_v1_deck_service_proto_rawDescGZIP() []byte { + file_transport_v1_deck_service_proto_rawDescOnce.Do(func() { + file_transport_v1_deck_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_v1_deck_service_proto_rawDescData) + }) + return file_transport_v1_deck_service_proto_rawDescData +} + +var file_transport_v1_deck_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_transport_v1_deck_service_proto_goTypes = []interface{}{ + (*CreateDeckRequest)(nil), // 0: transport.v1.CreateDeckRequest + (*CreateDeckResponse)(nil), // 1: transport.v1.CreateDeckResponse + (*OpenDeckRequest)(nil), // 2: transport.v1.OpenDeckRequest + (*OpenDeckResponse)(nil), // 3: transport.v1.OpenDeckResponse + (*DrawCardsRequest)(nil), // 4: transport.v1.DrawCardsRequest + (*DrawCardsResponse)(nil), // 5: transport.v1.DrawCardsResponse + (*ShuffleDeckRequest)(nil), // 6: transport.v1.ShuffleDeckRequest + (*ShuffleDeckResponse)(nil), // 7: transport.v1.ShuffleDeckResponse + (*DeckClosed)(nil), // 8: transport.v1.DeckClosed + (*DeckOpened)(nil), // 9: transport.v1.DeckOpened + (*Card)(nil), // 10: transport.v1.Card +} +var file_transport_v1_deck_service_proto_depIdxs = []int32{ + 8, // 0: transport.v1.CreateDeckResponse.deck:type_name -> transport.v1.DeckClosed + 9, // 1: transport.v1.OpenDeckResponse.deck:type_name -> transport.v1.DeckOpened + 10, // 2: transport.v1.DrawCardsResponse.cards:type_name -> transport.v1.Card + 0, // 3: transport.v1.DeckService.CreateDeck:input_type -> transport.v1.CreateDeckRequest + 2, // 4: transport.v1.DeckService.OpenDeck:input_type -> transport.v1.OpenDeckRequest + 4, // 5: transport.v1.DeckService.DrawCards:input_type -> transport.v1.DrawCardsRequest + 6, // 6: transport.v1.DeckService.ShuffleDeck:input_type -> transport.v1.ShuffleDeckRequest + 1, // 7: transport.v1.DeckService.CreateDeck:output_type -> transport.v1.CreateDeckResponse + 3, // 8: transport.v1.DeckService.OpenDeck:output_type -> transport.v1.OpenDeckResponse + 5, // 9: transport.v1.DeckService.DrawCards:output_type -> transport.v1.DrawCardsResponse + 7, // 10: transport.v1.DeckService.ShuffleDeck:output_type -> transport.v1.ShuffleDeckResponse + 7, // [7:11] is the sub-list for method output_type + 3, // [3:7] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_transport_v1_deck_service_proto_init() } +func file_transport_v1_deck_service_proto_init() { + if File_transport_v1_deck_service_proto != nil { + return + } + file_transport_v1_deck_proto_init() + if !protoimpl.UnsafeEnabled { + file_transport_v1_deck_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateDeckRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateDeckResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OpenDeckRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OpenDeckResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DrawCardsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DrawCardsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShuffleDeckRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_transport_v1_deck_service_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShuffleDeckResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_transport_v1_deck_service_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_transport_v1_deck_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 8, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_transport_v1_deck_service_proto_goTypes, + DependencyIndexes: file_transport_v1_deck_service_proto_depIdxs, + MessageInfos: file_transport_v1_deck_service_proto_msgTypes, + }.Build() + File_transport_v1_deck_service_proto = out.File + file_transport_v1_deck_service_proto_rawDesc = nil + file_transport_v1_deck_service_proto_goTypes = nil + file_transport_v1_deck_service_proto_depIdxs = nil +} diff --git a/transport/v1/deck_service.pb.gw.go b/transport/v1/deck_service.pb.gw.go new file mode 100644 index 0000000..0653bec --- /dev/null +++ b/transport/v1/deck_service.pb.gw.go @@ -0,0 +1,494 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: transport/v1/deck_service.proto + +/* +Package v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +var ( + filter_DeckService_CreateDeck_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_DeckService_CreateDeck_0(ctx context.Context, marshaler runtime.Marshaler, client DeckServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateDeckRequest + 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_DeckService_CreateDeck_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CreateDeck(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_DeckService_CreateDeck_0(ctx context.Context, marshaler runtime.Marshaler, server DeckServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateDeckRequest + 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_DeckService_CreateDeck_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CreateDeck(ctx, &protoReq) + return msg, metadata, err + +} + +func request_DeckService_OpenDeck_0(ctx context.Context, marshaler runtime.Marshaler, client DeckServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq OpenDeckRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.OpenDeck(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_DeckService_OpenDeck_0(ctx context.Context, marshaler runtime.Marshaler, server DeckServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq OpenDeckRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.OpenDeck(ctx, &protoReq) + return msg, metadata, err + +} + +func request_DeckService_DrawCards_0(ctx context.Context, marshaler runtime.Marshaler, client DeckServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DrawCardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + val, ok = pathParams["num"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "num") + } + + protoReq.Num, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "num", err) + } + + msg, err := client.DrawCards(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_DeckService_DrawCards_0(ctx context.Context, marshaler runtime.Marshaler, server DeckServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DrawCardsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + val, ok = pathParams["num"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "num") + } + + protoReq.Num, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "num", err) + } + + msg, err := server.DrawCards(ctx, &protoReq) + return msg, metadata, err + +} + +func request_DeckService_ShuffleDeck_0(ctx context.Context, marshaler runtime.Marshaler, client DeckServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ShuffleDeckRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.ShuffleDeck(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_DeckService_ShuffleDeck_0(ctx context.Context, marshaler runtime.Marshaler, server DeckServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ShuffleDeckRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.ShuffleDeck(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterDeckServiceHandlerServer registers the http handlers for service DeckService to "mux". +// UnaryRPC :call DeckServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterDeckServiceHandlerFromEndpoint instead. +func RegisterDeckServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server DeckServiceServer) error { + + mux.Handle("POST", pattern_DeckService_CreateDeck_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/transport.v1.DeckService/CreateDeck", runtime.WithHTTPPathPattern("/v1/decks")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_DeckService_CreateDeck_0(ctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_CreateDeck_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_DeckService_OpenDeck_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/transport.v1.DeckService/OpenDeck", runtime.WithHTTPPathPattern("/v1/decks/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_DeckService_OpenDeck_0(ctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_OpenDeck_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("PATCH", pattern_DeckService_DrawCards_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/transport.v1.DeckService/DrawCards", runtime.WithHTTPPathPattern("/v1/decks/{id}/draw/{num}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_DeckService_DrawCards_0(ctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_DrawCards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_DeckService_ShuffleDeck_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/transport.v1.DeckService/ShuffleDeck", runtime.WithHTTPPathPattern("/v1/decks/{id}/shuffle")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_DeckService_ShuffleDeck_0(ctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_ShuffleDeck_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterDeckServiceHandlerFromEndpoint is same as RegisterDeckServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterDeckServiceHandlerFromEndpoint(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 RegisterDeckServiceHandler(ctx, mux, conn) +} + +// RegisterDeckServiceHandler registers the http handlers for service DeckService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterDeckServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterDeckServiceHandlerClient(ctx, mux, NewDeckServiceClient(conn)) +} + +// RegisterDeckServiceHandlerClient registers the http handlers for service DeckService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "DeckServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "DeckServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "DeckServiceClient" to call the correct interceptors. +func RegisterDeckServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client DeckServiceClient) error { + + mux.Handle("POST", pattern_DeckService_CreateDeck_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) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/transport.v1.DeckService/CreateDeck", runtime.WithHTTPPathPattern("/v1/decks")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_DeckService_CreateDeck_0(ctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_CreateDeck_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_DeckService_OpenDeck_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) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/transport.v1.DeckService/OpenDeck", runtime.WithHTTPPathPattern("/v1/decks/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_DeckService_OpenDeck_0(ctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_OpenDeck_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("PATCH", pattern_DeckService_DrawCards_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) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/transport.v1.DeckService/DrawCards", runtime.WithHTTPPathPattern("/v1/decks/{id}/draw/{num}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_DeckService_DrawCards_0(ctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_DrawCards_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_DeckService_ShuffleDeck_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) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/transport.v1.DeckService/ShuffleDeck", runtime.WithHTTPPathPattern("/v1/decks/{id}/shuffle")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_DeckService_ShuffleDeck_0(ctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_DeckService_ShuffleDeck_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_DeckService_CreateDeck_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "decks"}, "")) + + pattern_DeckService_OpenDeck_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "decks", "id"}, "")) + + pattern_DeckService_DrawCards_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "decks", "id", "draw", "num"}, "")) + + pattern_DeckService_ShuffleDeck_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "decks", "id", "shuffle"}, "")) +) + +var ( + forward_DeckService_CreateDeck_0 = runtime.ForwardResponseMessage + + forward_DeckService_OpenDeck_0 = runtime.ForwardResponseMessage + + forward_DeckService_DrawCards_0 = runtime.ForwardResponseMessage + + forward_DeckService_ShuffleDeck_0 = runtime.ForwardResponseMessage +) diff --git a/transport/v1/deck_service.proto b/transport/v1/deck_service.proto new file mode 100644 index 0000000..8f93d31 --- /dev/null +++ b/transport/v1/deck_service.proto @@ -0,0 +1,262 @@ +syntax = "proto3"; + +package transport.v1; + +option go_package = "github.com/mgjules/deckr/transport/v1;v1"; + +import "transport/v1/deck.proto"; +import "google/api/annotations.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: { + title: "Deckr"; + version: "v0.3.2"; + description: "A REST/gRPC API for playing with a deck of cards."; + contact: { + name: "Michaël Giovanni Jules"; + url: "https://mgjules.dev"; + email: "julesmichaelgiovanni@gmail.com"; + }; + license: { + name: "Apache 2.0 License"; + url: "https://github.com/mgjules/deckr/blob/master/LICENSE"; + }; + }; + schemes: HTTP; + consumes: "application/json"; + produces: "application/json"; +}; + +// CreateDeckRequest holds the composition and optional codes needed to create a deck. +message CreateDeckRequest { + optional string comp = 1; + repeated string codes = 2; +} + +// CreateDeckResponse holds the deck created. +message CreateDeckResponse { + DeckClosed deck = 1; +} + +// OpenDeckRequest holds the deck id needed to open a deck. +message OpenDeckRequest { string id = 1; } + +// OpenDeckResponse holds the deck opened. +message OpenDeckResponse { + DeckOpened deck = 1; +} + +// DrawCardsRequest holds the id of the deck and number of cards to draw from the deck. +message DrawCardsRequest { + string id = 1; + int32 num = 2; +} + +// DrawCardsResponse holds the cards drawn. +message DrawCardsResponse { + repeated Card cards = 1; +} + +// ShuffleDeckRequest holds the id of the deck to shuffle. +message ShuffleDeckRequest { string id = 1; } + +// ShuffleDeckResponse holds the message after shuffling a deck. +message ShuffleDeckResponse { string message = 1; } + +service DeckService { + // CreateDeck creates a new full or partial deck of cards given an optional + // list of codes. + rpc CreateDeck(CreateDeckRequest) returns (CreateDeckResponse) { + option (google.api.http) = { + post: "/v1/decks" + }; + + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { + summary: "creates a new full or partial deck of cards given an optional list of codes."; + operation_id: "CreateDeck"; + responses: { + key: "200" + value: { + description: "A freshly created deck." + } + }; + responses: { + key: "400" + value: { + description: "The request was malformed." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "500" + value: { + description: "Internal server error." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + }; + } + + // OpenDeck opens a deck of cards given an id. + rpc OpenDeck(OpenDeckRequest) returns (OpenDeckResponse) { + option (google.api.http) = { + get: "/v1/decks/{id}" + }; + + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { + summary: "opens a deck of cards given an id."; + operation_id: "OpenDeck"; + responses: { + key: "200" + value: { + description: "A deck." + } + }; + responses: { + key: "400" + value: { + description: "The request was malformed." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "404" + value: { + description: "Deck not found." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "500" + value: { + description: "Internal server error." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + }; + } + + // DrawCards draws cards from a deck of cards given an id and the number of + // cards. + rpc DrawCards(DrawCardsRequest) returns (DrawCardsResponse) { + option (google.api.http) = { + patch: "/v1/decks/{id}/draw/{num}" + }; + + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { + summary: "draws cards from a deck of cards given an id and the number of cards."; + operation_id: "DrawCards"; + responses: { + key: "200" + value: { + description: "A list of cards." + } + }; + responses: { + key: "400" + value: { + description: "The request was malformed." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "404" + value: { + description: "Deck not found." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "500" + value: { + description: "Internal server error." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + }; + } + + // ShuffleDeck shuffles a deck of cards given an id. + rpc ShuffleDeck(ShuffleDeckRequest) returns (ShuffleDeckResponse) { + option (google.api.http) = { + post: "/v1/decks/{id}/shuffle" + }; + + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { + summary: "shuffles a deck of cards given an id."; + operation_id: "ShuffleDeck"; + responses: { + key: "200" + value: { + description: "A successful response." + } + }; + responses: { + key: "400" + value: { + description: "The request was malformed." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "404" + value: { + description: "Deck not found." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + responses: { + key: "500" + value: { + description: "Internal server error." + schema: { + json_schema: { + ref: "#/definitions/rpcStatus" + } + } + } + }; + }; + } +} \ No newline at end of file diff --git a/transport/v1/deck_service.swagger.json b/transport/v1/deck_service.swagger.json new file mode 100644 index 0000000..e234a24 --- /dev/null +++ b/transport/v1/deck_service.swagger.json @@ -0,0 +1,361 @@ +{ + "swagger": "2.0", + "info": { + "title": "Deckr", + "description": "A REST/gRPC API for playing with a deck of cards.", + "version": "v0.3.2", + "contact": { + "name": "Michaël Giovanni Jules", + "url": "https://mgjules.dev", + "email": "julesmichaelgiovanni@gmail.com" + }, + "license": { + "name": "Apache 2.0 License", + "url": "https://github.com/mgjules/deckr/blob/master/LICENSE" + } + }, + "tags": [ + { + "name": "DeckService" + } + ], + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/decks": { + "post": { + "summary": "creates a new full or partial deck of cards given an optional list of codes.", + "operationId": "CreateDeck", + "responses": { + "200": { + "description": "A freshly created deck.", + "schema": { + "$ref": "#/definitions/v1CreateDeckResponse" + } + }, + "400": { + "description": "The request was malformed.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "500": { + "description": "Internal server error.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "comp", + "in": "query", + "required": false, + "type": "string" + }, + { + "name": "codes", + "in": "query", + "required": false, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi" + } + ], + "tags": [ + "DeckService" + ] + } + }, + "/v1/decks/{id}": { + "get": { + "summary": "opens a deck of cards given an id.", + "operationId": "OpenDeck", + "responses": { + "200": { + "description": "A deck.", + "schema": { + "$ref": "#/definitions/v1OpenDeckResponse" + } + }, + "400": { + "description": "The request was malformed.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "404": { + "description": "Deck not found.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "500": { + "description": "Internal server error.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "DeckService" + ] + } + }, + "/v1/decks/{id}/draw/{num}": { + "patch": { + "summary": "draws cards from a deck of cards given an id and the number of cards.", + "operationId": "DrawCards", + "responses": { + "200": { + "description": "A list of cards.", + "schema": { + "$ref": "#/definitions/v1DrawCardsResponse" + } + }, + "400": { + "description": "The request was malformed.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "404": { + "description": "Deck not found.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "500": { + "description": "Internal server error.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "num", + "in": "path", + "required": true, + "type": "integer", + "format": "int32" + } + ], + "tags": [ + "DeckService" + ] + } + }, + "/v1/decks/{id}/shuffle": { + "post": { + "summary": "shuffles a deck of cards given an id.", + "operationId": "ShuffleDeck", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1ShuffleDeckResponse" + } + }, + "400": { + "description": "The request was malformed.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "404": { + "description": "Deck not found.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "500": { + "description": "Internal server error.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "DeckService" + ] + } + } + }, + "definitions": { + "protobufAny": { + "type": "object", + "properties": { + "@type": { + "type": "string" + } + }, + "additionalProperties": {} + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + }, + "v1Card": { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "suit": { + "type": "string" + }, + "code": { + "type": "string" + } + }, + "description": "Card represents a single card." + }, + "v1CreateDeckResponse": { + "type": "object", + "properties": { + "deck": { + "$ref": "#/definitions/v1DeckClosed" + } + }, + "description": "CreateDeckResponse holds the deck created." + }, + "v1DeckClosed": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "shuffled": { + "type": "boolean" + }, + "remaining": { + "type": "integer", + "format": "int64" + } + }, + "description": "DeckClosed represents a closed deck of cards." + }, + "v1DeckOpened": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "shuffled": { + "type": "boolean" + }, + "remaining": { + "type": "integer", + "format": "int64" + }, + "cards": { + "type": "array", + "items": { + "$ref": "#/definitions/v1Card" + } + } + }, + "description": "DeckOpened represents a opened deck of cards." + }, + "v1DrawCardsResponse": { + "type": "object", + "properties": { + "cards": { + "type": "array", + "items": { + "$ref": "#/definitions/v1Card" + } + } + }, + "description": "DrawCardsResponse holds the cards drawn." + }, + "v1OpenDeckResponse": { + "type": "object", + "properties": { + "deck": { + "$ref": "#/definitions/v1DeckOpened" + } + }, + "description": "OpenDeckResponse holds the deck opened." + }, + "v1ShuffleDeckResponse": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + }, + "description": "ShuffleDeckResponse holds the message after shuffling a deck." + } + } +} diff --git a/transport/grpc/deck_service_grpc.pb.go b/transport/v1/deck_service_grpc.pb.go similarity index 92% rename from transport/grpc/deck_service_grpc.pb.go rename to transport/v1/deck_service_grpc.pb.go index d8ad9f1..b786521 100644 --- a/transport/grpc/deck_service_grpc.pb.go +++ b/transport/v1/deck_service_grpc.pb.go @@ -2,9 +2,9 @@ // versions: // - protoc-gen-go-grpc v1.2.0 // - protoc (unknown) -// source: transport/grpc/deck_service.proto +// source: transport/v1/deck_service.proto -package grpc +package v1 import ( context "context" @@ -44,7 +44,7 @@ func NewDeckServiceClient(cc grpc.ClientConnInterface) DeckServiceClient { func (c *deckServiceClient) CreateDeck(ctx context.Context, in *CreateDeckRequest, opts ...grpc.CallOption) (*CreateDeckResponse, error) { out := new(CreateDeckResponse) - err := c.cc.Invoke(ctx, "/grpc.DeckService/CreateDeck", in, out, opts...) + err := c.cc.Invoke(ctx, "/transport.v1.DeckService/CreateDeck", in, out, opts...) if err != nil { return nil, err } @@ -53,7 +53,7 @@ func (c *deckServiceClient) CreateDeck(ctx context.Context, in *CreateDeckReques func (c *deckServiceClient) OpenDeck(ctx context.Context, in *OpenDeckRequest, opts ...grpc.CallOption) (*OpenDeckResponse, error) { out := new(OpenDeckResponse) - err := c.cc.Invoke(ctx, "/grpc.DeckService/OpenDeck", in, out, opts...) + err := c.cc.Invoke(ctx, "/transport.v1.DeckService/OpenDeck", in, out, opts...) if err != nil { return nil, err } @@ -62,7 +62,7 @@ func (c *deckServiceClient) OpenDeck(ctx context.Context, in *OpenDeckRequest, o func (c *deckServiceClient) DrawCards(ctx context.Context, in *DrawCardsRequest, opts ...grpc.CallOption) (*DrawCardsResponse, error) { out := new(DrawCardsResponse) - err := c.cc.Invoke(ctx, "/grpc.DeckService/DrawCards", in, out, opts...) + err := c.cc.Invoke(ctx, "/transport.v1.DeckService/DrawCards", in, out, opts...) if err != nil { return nil, err } @@ -71,7 +71,7 @@ func (c *deckServiceClient) DrawCards(ctx context.Context, in *DrawCardsRequest, func (c *deckServiceClient) ShuffleDeck(ctx context.Context, in *ShuffleDeckRequest, opts ...grpc.CallOption) (*ShuffleDeckResponse, error) { out := new(ShuffleDeckResponse) - err := c.cc.Invoke(ctx, "/grpc.DeckService/ShuffleDeck", in, out, opts...) + err := c.cc.Invoke(ctx, "/transport.v1.DeckService/ShuffleDeck", in, out, opts...) if err != nil { return nil, err } @@ -134,7 +134,7 @@ func _DeckService_CreateDeck_Handler(srv interface{}, ctx context.Context, dec f } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/grpc.DeckService/CreateDeck", + FullMethod: "/transport.v1.DeckService/CreateDeck", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DeckServiceServer).CreateDeck(ctx, req.(*CreateDeckRequest)) @@ -152,7 +152,7 @@ func _DeckService_OpenDeck_Handler(srv interface{}, ctx context.Context, dec fun } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/grpc.DeckService/OpenDeck", + FullMethod: "/transport.v1.DeckService/OpenDeck", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DeckServiceServer).OpenDeck(ctx, req.(*OpenDeckRequest)) @@ -170,7 +170,7 @@ func _DeckService_DrawCards_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/grpc.DeckService/DrawCards", + FullMethod: "/transport.v1.DeckService/DrawCards", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DeckServiceServer).DrawCards(ctx, req.(*DrawCardsRequest)) @@ -188,7 +188,7 @@ func _DeckService_ShuffleDeck_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/grpc.DeckService/ShuffleDeck", + FullMethod: "/transport.v1.DeckService/ShuffleDeck", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DeckServiceServer).ShuffleDeck(ctx, req.(*ShuffleDeckRequest)) @@ -200,7 +200,7 @@ func _DeckService_ShuffleDeck_Handler(srv interface{}, ctx context.Context, dec // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) var DeckService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "grpc.DeckService", + ServiceName: "transport.v1.DeckService", HandlerType: (*DeckServiceServer)(nil), Methods: []grpc.MethodDesc{ { @@ -221,5 +221,5 @@ var DeckService_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "transport/grpc/deck_service.proto", + Metadata: "transport/v1/deck_service.proto", }