Delete unused files
This commit is contained in:
parent
fe6dae4c52
commit
6c1ee311cd
5 changed files with 0 additions and 917 deletions
|
@ -1,8 +0,0 @@
|
|||
FROM quay.io/goswagger/swagger:latest
|
||||
LABEL maintainer="Marc Di Luzio <marc.diluzio@gmail.com>"
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
CMD [ "serve", "pkg/rove/rove.swagger.json", "--no-open" ]
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
// +build integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mdiluz/rove/pkg/rove"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Server is a simple wrapper to a server path
|
||||
type Server string
|
||||
|
||||
// Request performs a HTTP
|
||||
func (s Server) Request(method, path string, in, out interface{}) error {
|
||||
u := url.URL{
|
||||
Scheme: "http",
|
||||
Host: fmt.Sprintf("%s:8080", 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(method, 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)
|
||||
}
|
||||
}
|
||||
|
||||
var serv = Server(os.Getenv("ROVE_HTTP"))
|
||||
|
||||
func TestServer_ServerStatus(t *testing.T) {
|
||||
req := &rove.ServerStatusRequest{}
|
||||
resp := &rove.ServerStatusResponse{}
|
||||
if err := serv.Request("GET", "server-status", req, resp); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_Register(t *testing.T) {
|
||||
req := &rove.RegisterRequest{Name: uuid.New().String()}
|
||||
resp := &rove.RegisterResponse{}
|
||||
err := serv.Request("POST", "register", req, resp)
|
||||
assert.NoError(t, err, "First register attempt should pass")
|
||||
err = serv.Request("POST", "register", req, resp)
|
||||
assert.Error(t, err, "Second identical register attempt should fail")
|
||||
}
|
||||
|
||||
func TestServer_Command(t *testing.T) {
|
||||
acc := uuid.New().String()
|
||||
var resp rove.RegisterResponse
|
||||
err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &resp)
|
||||
assert.NoError(t, err, "First register attempt should pass")
|
||||
|
||||
req := &rove.CommandRequest{
|
||||
Account: &rove.Account{
|
||||
Name: resp.Account.Name,
|
||||
},
|
||||
Commands: []*rove.Command{
|
||||
{
|
||||
Command: "move",
|
||||
Bearing: "NE",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Error(t, serv.Request("POST", "command", req, &rove.CommandResponse{}), "Commands should fail with no secret")
|
||||
|
||||
req.Account.Secret = resp.Account.Secret
|
||||
assert.NoError(t, serv.Request("POST", "command", req, &rove.CommandResponse{}), "Commands should pass")
|
||||
}
|
||||
|
||||
func TestServer_Radar(t *testing.T) {
|
||||
acc := uuid.New().String()
|
||||
var reg rove.RegisterResponse
|
||||
err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, ®)
|
||||
assert.NoError(t, err, "First register attempt should pass")
|
||||
|
||||
resp := &rove.RadarResponse{}
|
||||
req := &rove.RadarRequest{
|
||||
Account: &rove.Account{
|
||||
Name: reg.Account.Name,
|
||||
},
|
||||
}
|
||||
|
||||
assert.Error(t, serv.Request("POST", "radar", req, resp), "Radar should fail without secret")
|
||||
req.Account.Secret = reg.Account.Secret
|
||||
|
||||
assert.NoError(t, serv.Request("POST", "radar", req, resp), "Radar should pass")
|
||||
assert.NotZero(t, resp.Range, "Radar should return valid range")
|
||||
|
||||
w := int(resp.Range*2 + 1)
|
||||
assert.Equal(t, w*w, len(resp.Tiles), "radar should return correct number of tiles")
|
||||
assert.Equal(t, w*w, len(resp.Objects), "radar should return correct number of objects")
|
||||
}
|
||||
|
||||
func TestServer_Status(t *testing.T) {
|
||||
acc := uuid.New().String()
|
||||
var reg rove.RegisterResponse
|
||||
err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, ®)
|
||||
assert.NoError(t, err, "First register attempt should pass")
|
||||
|
||||
resp := &rove.StatusResponse{}
|
||||
req := &rove.StatusRequest{
|
||||
Account: &rove.Account{
|
||||
Name: reg.Account.Name,
|
||||
},
|
||||
}
|
||||
|
||||
assert.Error(t, serv.Request("POST", "status", req, resp), "Status should fail without secret")
|
||||
req.Account.Secret = reg.Account.Secret
|
||||
|
||||
assert.NoError(t, serv.Request("POST", "status", req, resp), "Status should pass")
|
||||
assert.NotZero(t, resp.Range, "Rover should return valid range")
|
||||
assert.NotZero(t, len(resp.Name), "Rover should return valid name")
|
||||
assert.NotZero(t, resp.Position, "Rover should return valid position")
|
||||
assert.NotZero(t, resp.Integrity, "Rover should have positive integrity")
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/rove"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
var endpoint = os.Getenv("ROVE_GRPC")
|
||||
if len(endpoint) == 0 {
|
||||
endpoint = "localhost:9090"
|
||||
}
|
||||
|
||||
var iport int
|
||||
var port = os.Getenv("PORT")
|
||||
if len(port) == 0 {
|
||||
iport = 8080
|
||||
} else {
|
||||
var err error
|
||||
iport, err = strconv.Atoi(port)
|
||||
if err != nil {
|
||||
log.Fatal("$PORT not valid int")
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new mux and register it with the gRPC endpoint
|
||||
fmt.Printf("Hosting reverse-proxy on %d for %s\n", iport, endpoint)
|
||||
mux := runtime.NewServeMux()
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
if err := rove.RegisterRoveHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Start the HTTP server and proxy calls to gRPC endpoint when needed
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", iport), mux); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -1,459 +0,0 @@
|
|||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: rove/rove.proto
|
||||
|
||||
/*
|
||||
Package rove is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package rove
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = descriptor.ForMessage
|
||||
|
||||
func request_Rove_ServerStatus_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ServerStatusRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.ServerStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Rove_ServerStatus_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ServerStatusRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.ServerStatus(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Rove_Register_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RegisterRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Register(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Rove_Register_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RegisterRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Register(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Rove_Command_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CommandRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Command(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Rove_Command_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CommandRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Command(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RadarRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Radar(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq RadarRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Radar(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Rove_Status_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq StatusRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Status(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Rove_Status_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq StatusRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Status(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterRoveHandlerServer registers the http handlers for service Rove to "mux".
|
||||
// UnaryRPC :call RoveServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
func RegisterRoveHandlerServer(ctx context.Context, mux *runtime.ServeMux, server RoveServer) error {
|
||||
|
||||
mux.Handle("GET", pattern_Rove_ServerStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Rove_ServerStatus_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_ServerStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Register_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Rove_Register_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Register_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Command_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Rove_Command_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Command_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Rove_Radar_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Radar_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Rove_Status_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterRoveHandlerFromEndpoint is same as RegisterRoveHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterRoveHandlerFromEndpoint(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 RegisterRoveHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterRoveHandler registers the http handlers for service Rove to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterRoveHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterRoveHandlerClient(ctx, mux, NewRoveClient(conn))
|
||||
}
|
||||
|
||||
// RegisterRoveHandlerClient registers the http handlers for service Rove
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "RoveClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "RoveClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "RoveClient" to call the correct interceptors.
|
||||
func RegisterRoveHandlerClient(ctx context.Context, mux *runtime.ServeMux, client RoveClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_Rove_ServerStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Rove_ServerStatus_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_ServerStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Register_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Rove_Register_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Register_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Command_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Rove_Command_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Command_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Rove_Radar_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Radar_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_Rove_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Rove_Status_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Rove_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Rove_ServerStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"server-status"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Rove_Register_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"register"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Rove_Command_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"command"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Rove_Radar_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"radar"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Rove_Status_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"status"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Rove_ServerStatus_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Rove_Register_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Rove_Command_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Rove_Radar_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Rove_Status_0 = runtime.ForwardResponseMessage
|
||||
)
|
|
@ -1,249 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Rove",
|
||||
"description": "Rove is an asychronous nomadic game about exploring a planet as part of a loose community",
|
||||
"version": "version not set"
|
||||
},
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roveAccount": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"secret": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roveCommand": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"command": {
|
||||
"$ref": "#/definitions/roveCommandType",
|
||||
"title": "The command type"
|
||||
},
|
||||
"bearing": {
|
||||
"type": "string",
|
||||
"title": "A bearing, example: NE\nUsed with MOVE"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"title": "A simple message, must be composed of printable ASCII glyphs (32-126)\nmaximum of three characters\nUsed with BROADCAST"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roveCommandResponse": {
|
||||
"type": "object",
|
||||
"title": "Empty placeholder"
|
||||
},
|
||||
"roveCommandType": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"none",
|
||||
"move",
|
||||
"stash",
|
||||
"repair",
|
||||
"recharge",
|
||||
"broadcast"
|
||||
],
|
||||
"default": "none",
|
||||
"title": "- move: Move the rover in a direction, requires bearing\n - stash: Stashes item at current location in rover inventory\n - repair: Repairs the rover using an inventory object\n - recharge: Waits a tick to add more charge to the rover\n - broadcast: Broadcasts a message to nearby rovers"
|
||||
},
|
||||
"roveLog": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"time": {
|
||||
"type": "string",
|
||||
"title": "The unix timestamp of the log"
|
||||
},
|
||||
"text": {
|
||||
"type": "string",
|
||||
"title": "The text of the log"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"objects": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"title": "A similar array to the tile array, but containing objects"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roveRegisterResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"account": {
|
||||
"$ref": "#/definitions/roveAccount",
|
||||
"title": "The registered account information"
|
||||
}
|
||||
},
|
||||
"title": "Empty placeholder"
|
||||
},
|
||||
"roveServerStatusResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"version": {
|
||||
"type": "string",
|
||||
"title": "The version of the server in v{major}.{minor}-{delta}-{sha} form"
|
||||
},
|
||||
"ready": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"title": "Whether the server is ready to accept requests"
|
||||
},
|
||||
"tickRate": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The tick rate of the server in minutes (how many minutes per tick)"
|
||||
},
|
||||
"currentTick": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The current tick of the server"
|
||||
},
|
||||
"next_tick": {
|
||||
"type": "string",
|
||||
"title": "The time the next tick will occur"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roveStatusResponse": {
|
||||
"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 and broadcasting"
|
||||
},
|
||||
"inventory": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"title": "The items in the rover inventory"
|
||||
},
|
||||
"capacity": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The capacity of the inventory"
|
||||
},
|
||||
"integrity": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The current health of the rover"
|
||||
},
|
||||
"maximumIntegrity": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The maximum health of the rover"
|
||||
},
|
||||
"charge": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The energy stored in the rover"
|
||||
},
|
||||
"maximumCharge": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "The max energy the rover can store"
|
||||
},
|
||||
"incomingCommands": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/roveCommand"
|
||||
},
|
||||
"title": "The set of currently incoming commands for this tick"
|
||||
},
|
||||
"queuedCommands": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/roveCommand"
|
||||
},
|
||||
"title": "The set of currently queued commands"
|
||||
},
|
||||
"logs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/roveLog"
|
||||
},
|
||||
"title": "The most recent logs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roveVector": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"y": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue