Migrate to gRPC rather than REST with swagger

Will also be adding in a RESTful endpoint to the server as well so it can consume both types
This commit is contained in:
Marc Di Luzio 2020-06-12 22:51:18 +01:00
parent b815284199
commit 7ababb79f6
23 changed files with 1110 additions and 1101 deletions

View file

@ -1,94 +0,0 @@
package rove
import (
"path"
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/game"
)
// ==============================
// API: /status method: GET
// Status queries the status of the server
func (s Server) Status() (r StatusResponse, err error) {
s.Get("status", &r)
return
}
// StatusResponse is a struct that contains information on the status of the server
type StatusResponse struct {
Ready bool `json:"ready"`
Version string `json:"version"`
Tick int `json:"tick"`
NextTick string `json:"nexttick,omitempty"`
}
// ==============================
// API: /register method: POST
// Register registers a user by name
func (s Server) Register(d RegisterData) (r RegisterResponse, err error) {
err = s.Post("register", d, &r)
return
}
// RegisterData describes the data to send when registering
type RegisterData struct {
Name string `json:"name"`
}
// RegisterResponse describes the response to a register request
type RegisterResponse struct {
// Placeholder for future information
}
// ==============================
// API: /{account}/command method: POST
// Command issues a set of commands from the user
func (s Server) Command(account string, d CommandData) (r CommandResponse, err error) {
err = s.Post(path.Join(account, "command"), d, &r)
return
}
// CommandData is a set of commands to execute in order
type CommandData struct {
Commands []game.Command `json:"commands"`
}
// CommandResponse is the response to be sent back
type CommandResponse struct {
// Placeholder for future information
}
// ================
// API: /{account}/radar method: GET
// Radar queries the current radar for the user
func (s Server) Radar(account string) (r RadarResponse, err error) {
err = s.Get(path.Join(account, "radar"), &r)
return
}
// RadarResponse describes the response to a /radar call
type RadarResponse struct {
// The set of positions for nearby non-empty tiles
Range int `json:"range"`
Tiles []atlas.Tile `json:"tiles"`
}
// ================
// API: /{account}/rover method: GET
// Rover queries the current state of the rover
func (s Server) Rover(account string) (r RoverResponse, err error) {
err = s.Get(path.Join(account, "rover"), &r)
return
}
// RoverResponse includes information about the rover in question
type RoverResponse struct {
// The current position of this rover
Attributes game.RoverAttributes `json:"attributes"`
}

View file

@ -1,73 +0,0 @@
package rove
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
// Server is a simple wrapper to a server path
type Server string
// Get performs a Get request
func (s Server) Get(path string, out interface{}) error {
u := url.URL{
Scheme: "http",
Host: string(s),
Path: path,
}
if resp, err := http.Get(u.String()); err != nil {
return err
} else if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response body to code %d", resp.StatusCode)
}
return fmt.Errorf("http returned status %d: %s", resp.StatusCode, string(body))
} else {
return json.NewDecoder(resp.Body).Decode(out)
}
}
// Post performs a Post request
func (s Server) Post(path string, in, out interface{}) error {
u := url.URL{
Scheme: "http",
Host: string(s),
Path: path,
}
client := &http.Client{}
// Marshal the input
marshalled, err := json.Marshal(in)
if err != nil {
return err
}
// Set up the request
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(marshalled))
if err != nil {
return err
}
// Do the POST
req.Header.Set("Content-Type", "application/json")
if resp, err := client.Do(req); err != nil {
return err
} else if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response body to code %d", resp.StatusCode)
}
return fmt.Errorf("http returned status %d: %s", resp.StatusCode, string(body))
} else {
return json.NewDecoder(resp.Body).Decode(out)
}
}

821
pkg/rove/rove.pb.go Normal file
View file

@ -0,0 +1,821 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: rove.proto
package rove
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
empty "github.com/golang/protobuf/ptypes/empty"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Command struct {
// The command to execute, currently only accepts move, which requires a bearing and a duration.
Command string `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"`
Bearing string `protobuf:"bytes,2,opt,name=bearing,proto3" json:"bearing,omitempty"`
Duration int32 `protobuf:"varint,3,opt,name=duration,proto3" json:"duration,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Command) Reset() { *m = Command{} }
func (m *Command) String() string { return proto.CompactTextString(m) }
func (*Command) ProtoMessage() {}
func (*Command) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{0}
}
func (m *Command) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Command.Unmarshal(m, b)
}
func (m *Command) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Command.Marshal(b, m, deterministic)
}
func (m *Command) XXX_Merge(src proto.Message) {
xxx_messageInfo_Command.Merge(m, src)
}
func (m *Command) XXX_Size() int {
return xxx_messageInfo_Command.Size(m)
}
func (m *Command) XXX_DiscardUnknown() {
xxx_messageInfo_Command.DiscardUnknown(m)
}
var xxx_messageInfo_Command proto.InternalMessageInfo
func (m *Command) GetCommand() string {
if m != nil {
return m.Command
}
return ""
}
func (m *Command) GetBearing() string {
if m != nil {
return m.Bearing
}
return ""
}
func (m *Command) GetDuration() int32 {
if m != nil {
return m.Duration
}
return 0
}
type CommandsRequest struct {
Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
Commands []*Command `protobuf:"bytes,2,rep,name=commands,proto3" json:"commands,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CommandsRequest) Reset() { *m = CommandsRequest{} }
func (m *CommandsRequest) String() string { return proto.CompactTextString(m) }
func (*CommandsRequest) ProtoMessage() {}
func (*CommandsRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{1}
}
func (m *CommandsRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CommandsRequest.Unmarshal(m, b)
}
func (m *CommandsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CommandsRequest.Marshal(b, m, deterministic)
}
func (m *CommandsRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_CommandsRequest.Merge(m, src)
}
func (m *CommandsRequest) XXX_Size() int {
return xxx_messageInfo_CommandsRequest.Size(m)
}
func (m *CommandsRequest) XXX_DiscardUnknown() {
xxx_messageInfo_CommandsRequest.DiscardUnknown(m)
}
var xxx_messageInfo_CommandsRequest proto.InternalMessageInfo
func (m *CommandsRequest) GetAccount() string {
if m != nil {
return m.Account
}
return ""
}
func (m *CommandsRequest) GetCommands() []*Command {
if m != nil {
return m.Commands
}
return nil
}
type Error struct {
// An explanation for the HTTP error returned
Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Error) Reset() { *m = Error{} }
func (m *Error) String() string { return proto.CompactTextString(m) }
func (*Error) ProtoMessage() {}
func (*Error) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{2}
}
func (m *Error) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Error.Unmarshal(m, b)
}
func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Error.Marshal(b, m, deterministic)
}
func (m *Error) XXX_Merge(src proto.Message) {
xxx_messageInfo_Error.Merge(m, src)
}
func (m *Error) XXX_Size() int {
return xxx_messageInfo_Error.Size(m)
}
func (m *Error) XXX_DiscardUnknown() {
xxx_messageInfo_Error.DiscardUnknown(m)
}
var xxx_messageInfo_Error proto.InternalMessageInfo
func (m *Error) GetError() string {
if m != nil {
return m.Error
}
return ""
}
type RadarRequest struct {
Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RadarRequest) Reset() { *m = RadarRequest{} }
func (m *RadarRequest) String() string { return proto.CompactTextString(m) }
func (*RadarRequest) ProtoMessage() {}
func (*RadarRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{3}
}
func (m *RadarRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RadarRequest.Unmarshal(m, b)
}
func (m *RadarRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RadarRequest.Marshal(b, m, deterministic)
}
func (m *RadarRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_RadarRequest.Merge(m, src)
}
func (m *RadarRequest) XXX_Size() int {
return xxx_messageInfo_RadarRequest.Size(m)
}
func (m *RadarRequest) XXX_DiscardUnknown() {
xxx_messageInfo_RadarRequest.DiscardUnknown(m)
}
var xxx_messageInfo_RadarRequest proto.InternalMessageInfo
func (m *RadarRequest) GetAccount() string {
if m != nil {
return m.Account
}
return ""
}
type RadarResponse struct {
// The range in tiles from the rover of the radar data
Range int32 `protobuf:"varint,1,opt,name=range,proto3" json:"range,omitempty"`
// A 1D array representing range*2 + 1 squared set of tiles, origin bottom left and in row->column order
Tiles []byte `protobuf:"bytes,2,opt,name=tiles,proto3" json:"tiles,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RadarResponse) Reset() { *m = RadarResponse{} }
func (m *RadarResponse) String() string { return proto.CompactTextString(m) }
func (*RadarResponse) ProtoMessage() {}
func (*RadarResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{4}
}
func (m *RadarResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RadarResponse.Unmarshal(m, b)
}
func (m *RadarResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RadarResponse.Marshal(b, m, deterministic)
}
func (m *RadarResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_RadarResponse.Merge(m, src)
}
func (m *RadarResponse) XXX_Size() int {
return xxx_messageInfo_RadarResponse.Size(m)
}
func (m *RadarResponse) XXX_DiscardUnknown() {
xxx_messageInfo_RadarResponse.DiscardUnknown(m)
}
var xxx_messageInfo_RadarResponse proto.InternalMessageInfo
func (m *RadarResponse) GetRange() int32 {
if m != nil {
return m.Range
}
return 0
}
func (m *RadarResponse) GetTiles() []byte {
if m != nil {
return m.Tiles
}
return nil
}
type RegisterRequest struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RegisterRequest) Reset() { *m = RegisterRequest{} }
func (m *RegisterRequest) String() string { return proto.CompactTextString(m) }
func (*RegisterRequest) ProtoMessage() {}
func (*RegisterRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{5}
}
func (m *RegisterRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RegisterRequest.Unmarshal(m, b)
}
func (m *RegisterRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RegisterRequest.Marshal(b, m, deterministic)
}
func (m *RegisterRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_RegisterRequest.Merge(m, src)
}
func (m *RegisterRequest) XXX_Size() int {
return xxx_messageInfo_RegisterRequest.Size(m)
}
func (m *RegisterRequest) XXX_DiscardUnknown() {
xxx_messageInfo_RegisterRequest.DiscardUnknown(m)
}
var xxx_messageInfo_RegisterRequest proto.InternalMessageInfo
func (m *RegisterRequest) GetName() string {
if m != nil {
return m.Name
}
return ""
}
type RoverRequest struct {
Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RoverRequest) Reset() { *m = RoverRequest{} }
func (m *RoverRequest) String() string { return proto.CompactTextString(m) }
func (*RoverRequest) ProtoMessage() {}
func (*RoverRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{6}
}
func (m *RoverRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RoverRequest.Unmarshal(m, b)
}
func (m *RoverRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RoverRequest.Marshal(b, m, deterministic)
}
func (m *RoverRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_RoverRequest.Merge(m, src)
}
func (m *RoverRequest) XXX_Size() int {
return xxx_messageInfo_RoverRequest.Size(m)
}
func (m *RoverRequest) XXX_DiscardUnknown() {
xxx_messageInfo_RoverRequest.DiscardUnknown(m)
}
var xxx_messageInfo_RoverRequest proto.InternalMessageInfo
func (m *RoverRequest) GetAccount() string {
if m != nil {
return m.Account
}
return ""
}
type RoverResponse struct {
// The name of the rover
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// Position of the rover in world coordinates
Position *Vector `protobuf:"bytes,2,opt,name=position,proto3" json:"position,omitempty"`
// The range of this rover's radar
Range int32 `protobuf:"varint,3,opt,name=range,proto3" json:"range,omitempty"`
// The speed the rover can move per tick
Speed int32 `protobuf:"varint,4,opt,name=speed,proto3" json:"speed,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RoverResponse) Reset() { *m = RoverResponse{} }
func (m *RoverResponse) String() string { return proto.CompactTextString(m) }
func (*RoverResponse) ProtoMessage() {}
func (*RoverResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{7}
}
func (m *RoverResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RoverResponse.Unmarshal(m, b)
}
func (m *RoverResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RoverResponse.Marshal(b, m, deterministic)
}
func (m *RoverResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_RoverResponse.Merge(m, src)
}
func (m *RoverResponse) XXX_Size() int {
return xxx_messageInfo_RoverResponse.Size(m)
}
func (m *RoverResponse) XXX_DiscardUnknown() {
xxx_messageInfo_RoverResponse.DiscardUnknown(m)
}
var xxx_messageInfo_RoverResponse proto.InternalMessageInfo
func (m *RoverResponse) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *RoverResponse) GetPosition() *Vector {
if m != nil {
return m.Position
}
return nil
}
func (m *RoverResponse) GetRange() int32 {
if m != nil {
return m.Range
}
return 0
}
func (m *RoverResponse) GetSpeed() int32 {
if m != nil {
return m.Speed
}
return 0
}
type StatusResponse struct {
// The time the next tick will occur
NextTick string `protobuf:"bytes,1,opt,name=next_tick,json=nextTick,proto3" json:"next_tick,omitempty"`
// Whether the server is ready to accept requests
Ready bool `protobuf:"varint,2,opt,name=ready,proto3" json:"ready,omitempty"`
// The tick rate of the server in minutes (how many minutes per tick)
Tick int32 `protobuf:"varint,3,opt,name=tick,proto3" json:"tick,omitempty"`
// The version of the server in v{major}.{minor}-{delta}-{sha} form
Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *StatusResponse) Reset() { *m = StatusResponse{} }
func (m *StatusResponse) String() string { return proto.CompactTextString(m) }
func (*StatusResponse) ProtoMessage() {}
func (*StatusResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{8}
}
func (m *StatusResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_StatusResponse.Unmarshal(m, b)
}
func (m *StatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_StatusResponse.Marshal(b, m, deterministic)
}
func (m *StatusResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_StatusResponse.Merge(m, src)
}
func (m *StatusResponse) XXX_Size() int {
return xxx_messageInfo_StatusResponse.Size(m)
}
func (m *StatusResponse) XXX_DiscardUnknown() {
xxx_messageInfo_StatusResponse.DiscardUnknown(m)
}
var xxx_messageInfo_StatusResponse proto.InternalMessageInfo
func (m *StatusResponse) GetNextTick() string {
if m != nil {
return m.NextTick
}
return ""
}
func (m *StatusResponse) GetReady() bool {
if m != nil {
return m.Ready
}
return false
}
func (m *StatusResponse) GetTick() int32 {
if m != nil {
return m.Tick
}
return 0
}
func (m *StatusResponse) GetVersion() string {
if m != nil {
return m.Version
}
return ""
}
type Vector struct {
X int32 `protobuf:"varint,1,opt,name=x,proto3" json:"x,omitempty"`
Y int32 `protobuf:"varint,2,opt,name=y,proto3" json:"y,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Vector) Reset() { *m = Vector{} }
func (m *Vector) String() string { return proto.CompactTextString(m) }
func (*Vector) ProtoMessage() {}
func (*Vector) Descriptor() ([]byte, []int) {
return fileDescriptor_cea399972d1e9fa7, []int{9}
}
func (m *Vector) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Vector.Unmarshal(m, b)
}
func (m *Vector) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Vector.Marshal(b, m, deterministic)
}
func (m *Vector) XXX_Merge(src proto.Message) {
xxx_messageInfo_Vector.Merge(m, src)
}
func (m *Vector) XXX_Size() int {
return xxx_messageInfo_Vector.Size(m)
}
func (m *Vector) XXX_DiscardUnknown() {
xxx_messageInfo_Vector.DiscardUnknown(m)
}
var xxx_messageInfo_Vector proto.InternalMessageInfo
func (m *Vector) GetX() int32 {
if m != nil {
return m.X
}
return 0
}
func (m *Vector) GetY() int32 {
if m != nil {
return m.Y
}
return 0
}
func init() {
proto.RegisterType((*Command)(nil), "rove.Command")
proto.RegisterType((*CommandsRequest)(nil), "rove.CommandsRequest")
proto.RegisterType((*Error)(nil), "rove.Error")
proto.RegisterType((*RadarRequest)(nil), "rove.RadarRequest")
proto.RegisterType((*RadarResponse)(nil), "rove.RadarResponse")
proto.RegisterType((*RegisterRequest)(nil), "rove.RegisterRequest")
proto.RegisterType((*RoverRequest)(nil), "rove.RoverRequest")
proto.RegisterType((*RoverResponse)(nil), "rove.RoverResponse")
proto.RegisterType((*StatusResponse)(nil), "rove.StatusResponse")
proto.RegisterType((*Vector)(nil), "rove.Vector")
}
func init() {
proto.RegisterFile("rove.proto", fileDescriptor_cea399972d1e9fa7)
}
var fileDescriptor_cea399972d1e9fa7 = []byte{
// 477 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x5d, 0x6b, 0xdb, 0x30,
0x14, 0x8d, 0x93, 0x38, 0x75, 0x6f, 0x92, 0x15, 0xb4, 0x6e, 0x98, 0x94, 0x41, 0x10, 0x1b, 0x64,
0x2f, 0x2e, 0x64, 0x2f, 0x83, 0x3e, 0x8e, 0xfe, 0x01, 0x75, 0x14, 0xf6, 0x34, 0x14, 0xfb, 0xce,
0x98, 0x36, 0x96, 0x2b, 0xc9, 0x21, 0xf9, 0x49, 0xfb, 0x97, 0x43, 0xba, 0xb2, 0x97, 0x94, 0x8d,
0xf6, 0xed, 0x9e, 0xab, 0xab, 0x73, 0xce, 0xfd, 0x00, 0xd0, 0x6a, 0x87, 0x59, 0xa3, 0x95, 0x55,
0x6c, 0xec, 0xe2, 0xc5, 0x55, 0xa9, 0x54, 0xf9, 0x88, 0xd7, 0x3e, 0xb7, 0x69, 0x7f, 0x5d, 0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9f,
0x00, 0x00, 0x00, 0xff, 0xff, 0xed, 0x84, 0x22, 0xdd, 0x01, 0x04, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// RoverServerClient is the client API for RoverServer service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type RoverServerClient interface {
// Send commands to rover
//
// Sending commands to this endpoint will queue them to be executed during the following ticks, in the order sent
Commands(ctx context.Context, in *CommandsRequest, opts ...grpc.CallOption) (*empty.Empty, error)
// Get radar information
//
// Gets the radar output for the given rover
Radar(ctx context.Context, in *RadarRequest, opts ...grpc.CallOption) (*RadarResponse, error)
// Register an account
//
// Tries to register an account with the given name
Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*empty.Empty, error)
// Get rover information
//
// Gets information for the account's rover
Rover(ctx context.Context, in *RoverRequest, opts ...grpc.CallOption) (*RoverResponse, error)
// Server status
//
// Responds with various details about the current server status
Status(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*StatusResponse, error)
}
type roverServerClient struct {
cc grpc.ClientConnInterface
}
func NewRoverServerClient(cc grpc.ClientConnInterface) RoverServerClient {
return &roverServerClient{cc}
}
func (c *roverServerClient) Commands(ctx context.Context, in *CommandsRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
out := new(empty.Empty)
err := c.cc.Invoke(ctx, "/rove.RoverServer/Commands", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *roverServerClient) Radar(ctx context.Context, in *RadarRequest, opts ...grpc.CallOption) (*RadarResponse, error) {
out := new(RadarResponse)
err := c.cc.Invoke(ctx, "/rove.RoverServer/Radar", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *roverServerClient) Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
out := new(empty.Empty)
err := c.cc.Invoke(ctx, "/rove.RoverServer/Register", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *roverServerClient) Rover(ctx context.Context, in *RoverRequest, opts ...grpc.CallOption) (*RoverResponse, error) {
out := new(RoverResponse)
err := c.cc.Invoke(ctx, "/rove.RoverServer/Rover", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *roverServerClient) Status(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*StatusResponse, error) {
out := new(StatusResponse)
err := c.cc.Invoke(ctx, "/rove.RoverServer/Status", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// RoverServerServer is the server API for RoverServer service.
type RoverServerServer interface {
// Send commands to rover
//
// Sending commands to this endpoint will queue them to be executed during the following ticks, in the order sent
Commands(context.Context, *CommandsRequest) (*empty.Empty, error)
// Get radar information
//
// Gets the radar output for the given rover
Radar(context.Context, *RadarRequest) (*RadarResponse, error)
// Register an account
//
// Tries to register an account with the given name
Register(context.Context, *RegisterRequest) (*empty.Empty, error)
// Get rover information
//
// Gets information for the account's rover
Rover(context.Context, *RoverRequest) (*RoverResponse, error)
// Server status
//
// Responds with various details about the current server status
Status(context.Context, *empty.Empty) (*StatusResponse, error)
}
// UnimplementedRoverServerServer can be embedded to have forward compatible implementations.
type UnimplementedRoverServerServer struct {
}
func (*UnimplementedRoverServerServer) Commands(ctx context.Context, req *CommandsRequest) (*empty.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Commands not implemented")
}
func (*UnimplementedRoverServerServer) Radar(ctx context.Context, req *RadarRequest) (*RadarResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Radar not implemented")
}
func (*UnimplementedRoverServerServer) Register(ctx context.Context, req *RegisterRequest) (*empty.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Register not implemented")
}
func (*UnimplementedRoverServerServer) Rover(ctx context.Context, req *RoverRequest) (*RoverResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Rover not implemented")
}
func (*UnimplementedRoverServerServer) Status(ctx context.Context, req *empty.Empty) (*StatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Status not implemented")
}
func RegisterRoverServerServer(s *grpc.Server, srv RoverServerServer) {
s.RegisterService(&_RoverServer_serviceDesc, srv)
}
func _RoverServer_Commands_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CommandsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RoverServerServer).Commands(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rove.RoverServer/Commands",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RoverServerServer).Commands(ctx, req.(*CommandsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RoverServer_Radar_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RadarRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RoverServerServer).Radar(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rove.RoverServer/Radar",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RoverServerServer).Radar(ctx, req.(*RadarRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RoverServer_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RegisterRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RoverServerServer).Register(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rove.RoverServer/Register",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RoverServerServer).Register(ctx, req.(*RegisterRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RoverServer_Rover_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RoverRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RoverServerServer).Rover(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rove.RoverServer/Rover",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RoverServerServer).Rover(ctx, req.(*RoverRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RoverServer_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(empty.Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RoverServerServer).Status(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rove.RoverServer/Status",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RoverServerServer).Status(ctx, req.(*empty.Empty))
}
return interceptor(ctx, in, info, handler)
}
var _RoverServer_serviceDesc = grpc.ServiceDesc{
ServiceName: "rove.RoverServer",
HandlerType: (*RoverServerServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Commands",
Handler: _RoverServer_Commands_Handler,
},
{
MethodName: "Radar",
Handler: _RoverServer_Radar_Handler,
},
{
MethodName: "Register",
Handler: _RoverServer_Register_Handler,
},
{
MethodName: "Rover",
Handler: _RoverServer_Rover_Handler,
},
{
MethodName: "Status",
Handler: _RoverServer_Status_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "rove.proto",
}

103
pkg/rove/rove.proto Normal file
View file

@ -0,0 +1,103 @@
syntax = "proto3";
package rove;
import "google/protobuf/empty.proto";
service RoverServer {
// 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) {}
// Get radar information
//
// Gets the radar output for the given rover
rpc Radar(RadarRequest) returns (RadarResponse) {}
// Register an account
//
// Tries to register an account with the given name
rpc Register(RegisterRequest) returns (google.protobuf.Empty) {}
// Get rover information
//
// Gets information for the account's rover
rpc Rover(RoverRequest) returns (RoverResponse) {}
// Server status
//
// Responds with various details about the current server status
rpc Status(google.protobuf.Empty) returns (StatusResponse) {}
}
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;
}