Implement a reverse proxy using grpc-gateway

This commit is contained in:
Marc Di Luzio 2020-06-13 00:23:21 +01:00
parent 7ababb79f6
commit 8c6230ca20
22 changed files with 3122 additions and 802 deletions

128
proto/rove/rove.proto Normal file
View file

@ -0,0 +1,128 @@
syntax = "proto3";
package rove;
option go_package = "github.com/mdiluz/rove/pkg/rove";
import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
service RoveServer {
// Server status
//
// Responds with various details about the current server status
rpc Status(google.protobuf.Empty) returns (StatusResponse) {
option (google.api.http) = {
get: "/status"
};
}
// Register an account
//
// Tries to register an account with the given name
rpc Register(RegisterRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/register"
body: "*"
};
}
// Send commands to rover
//
// Sending commands to this endpoint will queue them to be executed during the following ticks, in the order sent
rpc Commands(CommandsRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/commands"
body: "*"
};
}
// Get radar information
//
// Gets the radar output for the given rover
rpc Radar(RadarRequest) returns (RadarResponse) {
option (google.api.http) = {
get: "/radar"
};
}
// Get rover information
//
// Gets information for the account's rover
rpc Rover(RoverRequest) returns (RoverResponse) {
option (google.api.http) = {
get: "/rover"
};
}
}
message Command {
// The command to execute, currently only accepts move, which requires a bearing and a duration.
string command = 1;
string bearing = 2;
int32 duration = 3;
}
message CommandsRequest {
string account = 1;
repeated Command commands = 2;
}
message Error {
// An explanation for the HTTP error returned
string error = 1;
}
message RadarRequest {
string account = 1;
}
message RadarResponse {
// The range in tiles from the rover of the radar data
int32 range = 1;
// A 1D array representing range*2 + 1 squared set of tiles, origin bottom left and in row->column order
bytes tiles = 2;
}
message RegisterRequest {
string name = 1;
}
message RoverRequest {
string account = 1;
}
message RoverResponse {
// The name of the rover
string name = 1;
// Position of the rover in world coordinates
Vector position = 2;
// The range of this rover's radar
int32 range = 3;
// The speed the rover can move per tick
int32 speed = 4;
}
message StatusResponse {
// The time the next tick will occur
string next_tick = 1;
// Whether the server is ready to accept requests
bool ready = 2;
// The tick rate of the server in minutes (how many minutes per tick)
int32 tick = 3;
// The version of the server in v{major}.{minor}-{delta}-{sha} form
string version = 4;
}
message Vector {
int32 x = 1;
int32 y = 2;
}

View file

@ -0,0 +1,318 @@
{
"swagger": "2.0",
"info": {
"title": "rove/rove.proto",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/commands": {
"post": {
"summary": "Send commands to rover",
"description": "Sending commands to this endpoint will queue them to be executed during the following ticks, in the order sent",
"operationId": "RoveServer_Commands",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"properties": {}
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/roveCommandsRequest"
}
}
],
"tags": [
"RoveServer"
]
}
},
"/radar": {
"get": {
"summary": "Get radar information",
"description": "Gets the radar output for the given rover",
"operationId": "RoveServer_Radar",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveRadarResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "account",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"RoveServer"
]
}
},
"/register": {
"post": {
"summary": "Register an account",
"description": "Tries to register an account with the given name",
"operationId": "RoveServer_Register",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"properties": {}
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/roveRegisterRequest"
}
}
],
"tags": [
"RoveServer"
]
}
},
"/rover": {
"get": {
"summary": "Get rover information",
"description": "Gets information for the account's rover",
"operationId": "RoveServer_Rover",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveRoverResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "account",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"RoveServer"
]
}
},
"/status": {
"get": {
"summary": "Server status",
"description": "Responds with various details about the current server status",
"operationId": "RoveServer_Status",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveStatusResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"tags": [
"RoveServer"
]
}
}
},
"definitions": {
"gatewayruntimeError": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufAny"
}
}
}
},
"protobufAny": {
"type": "object",
"properties": {
"type_url": {
"type": "string"
},
"value": {
"type": "string",
"format": "byte"
}
}
},
"roveCommand": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The command to execute, currently only accepts move, which requires a bearing and a duration."
},
"bearing": {
"type": "string"
},
"duration": {
"type": "integer",
"format": "int32"
}
}
},
"roveCommandsRequest": {
"type": "object",
"properties": {
"account": {
"type": "string"
},
"commands": {
"type": "array",
"items": {
"$ref": "#/definitions/roveCommand"
}
}
}
},
"roveRadarResponse": {
"type": "object",
"properties": {
"range": {
"type": "integer",
"format": "int32",
"title": "The range in tiles from the rover of the radar data"
},
"tiles": {
"type": "string",
"format": "byte",
"title": "A 1D array representing range*2 + 1 squared set of tiles, origin bottom left and in row-\u003ecolumn order"
}
}
},
"roveRegisterRequest": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"roveRoverResponse": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "The name of the rover"
},
"position": {
"$ref": "#/definitions/roveVector",
"title": "Position of the rover in world coordinates"
},
"range": {
"type": "integer",
"format": "int32",
"title": "The range of this rover's radar"
},
"speed": {
"type": "integer",
"format": "int32",
"title": "The speed the rover can move per tick"
}
}
},
"roveStatusResponse": {
"type": "object",
"properties": {
"next_tick": {
"type": "string",
"title": "The time the next tick will occur"
},
"ready": {
"type": "boolean",
"format": "boolean",
"title": "Whether the server is ready to accept requests"
},
"tick": {
"type": "integer",
"format": "int32",
"title": "The tick rate of the server in minutes (how many minutes per tick)"
},
"version": {
"type": "string",
"title": "The version of the server in v{major}.{minor}-{delta}-{sha} form"
}
}
},
"roveVector": {
"type": "object",
"properties": {
"x": {
"type": "integer",
"format": "int32"
},
"y": {
"type": "integer",
"format": "int32"
}
}
}
}
}