mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-18 21:55:08 +00:00
Space API (#290)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -42,7 +42,12 @@ func NewSpaceEndpoints() []*api.Endpoint {
|
||||
// Client API for Space service
|
||||
|
||||
type SpaceService interface {
|
||||
Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error)
|
||||
Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error)
|
||||
Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error)
|
||||
Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error)
|
||||
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
|
||||
Head(ctx context.Context, in *HeadRequest, opts ...client.CallOption) (*HeadResponse, error)
|
||||
Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error)
|
||||
}
|
||||
|
||||
type spaceService struct {
|
||||
@@ -57,9 +62,59 @@ func NewSpaceService(name string, c client.Client) SpaceService {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *spaceService) Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.Vote", in)
|
||||
out := new(VoteResponse)
|
||||
func (c *spaceService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.Create", in)
|
||||
out := new(CreateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *spaceService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.Update", in)
|
||||
out := new(UpdateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *spaceService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.Delete", in)
|
||||
out := new(DeleteResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *spaceService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.List", in)
|
||||
out := new(ListResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *spaceService) Head(ctx context.Context, in *HeadRequest, opts ...client.CallOption) (*HeadResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.Head", in)
|
||||
out := new(HeadResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *spaceService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Space.Read", in)
|
||||
out := new(ReadResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -70,12 +125,22 @@ func (c *spaceService) Vote(ctx context.Context, in *VoteRequest, opts ...client
|
||||
// Server API for Space service
|
||||
|
||||
type SpaceHandler interface {
|
||||
Vote(context.Context, *VoteRequest, *VoteResponse) error
|
||||
Create(context.Context, *CreateRequest, *CreateResponse) error
|
||||
Update(context.Context, *UpdateRequest, *UpdateResponse) error
|
||||
Delete(context.Context, *DeleteRequest, *DeleteResponse) error
|
||||
List(context.Context, *ListRequest, *ListResponse) error
|
||||
Head(context.Context, *HeadRequest, *HeadResponse) error
|
||||
Read(context.Context, *ReadRequest, *ReadResponse) error
|
||||
}
|
||||
|
||||
func RegisterSpaceHandler(s server.Server, hdlr SpaceHandler, opts ...server.HandlerOption) error {
|
||||
type space interface {
|
||||
Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error
|
||||
Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error
|
||||
Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error
|
||||
Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error
|
||||
List(ctx context.Context, in *ListRequest, out *ListResponse) error
|
||||
Head(ctx context.Context, in *HeadRequest, out *HeadResponse) error
|
||||
Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error
|
||||
}
|
||||
type Space struct {
|
||||
space
|
||||
@@ -88,6 +153,26 @@ type spaceHandler struct {
|
||||
SpaceHandler
|
||||
}
|
||||
|
||||
func (h *spaceHandler) Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error {
|
||||
return h.SpaceHandler.Vote(ctx, in, out)
|
||||
func (h *spaceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error {
|
||||
return h.SpaceHandler.Create(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *spaceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error {
|
||||
return h.SpaceHandler.Update(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *spaceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
|
||||
return h.SpaceHandler.Delete(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *spaceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error {
|
||||
return h.SpaceHandler.List(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *spaceHandler) Head(ctx context.Context, in *HeadRequest, out *HeadResponse) error {
|
||||
return h.SpaceHandler.Head(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *spaceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error {
|
||||
return h.SpaceHandler.Read(ctx, in, out)
|
||||
}
|
||||
|
||||
@@ -5,16 +5,100 @@ package space;
|
||||
option go_package = "./proto;space";
|
||||
|
||||
service Space {
|
||||
rpc Vote(VoteRequest) returns (VoteResponse) {}
|
||||
rpc Create(CreateRequest) returns (CreateResponse) {}
|
||||
rpc Update(UpdateRequest) returns (UpdateResponse) {}
|
||||
rpc Delete(DeleteRequest) returns (DeleteResponse) {}
|
||||
rpc List(ListRequest) returns (ListResponse) {}
|
||||
rpc Head(HeadRequest) returns (HeadResponse) {}
|
||||
rpc Read(ReadRequest) returns (ReadResponse) {}
|
||||
}
|
||||
|
||||
// Vote to have the Space api launched faster!
|
||||
message VoteRequest {
|
||||
// optional message
|
||||
string message = 1;
|
||||
// Create an object. Returns error if object with this name already exists. If you want to update an existing object use the `Update` endpoint
|
||||
// You need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
message CreateRequest {
|
||||
// The contents of the object
|
||||
bytes object = 1;
|
||||
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
|
||||
string name = 2;
|
||||
// Who can see this object? "public" or "private", defaults to "private"
|
||||
string visibility = 3;
|
||||
}
|
||||
|
||||
message VoteResponse {
|
||||
// response message
|
||||
string message = 2;
|
||||
message CreateResponse {
|
||||
// A public URL to access the object if visibility is "public"
|
||||
string url = 1;
|
||||
}
|
||||
|
||||
// Update an object. If an object with this name does not exist, creates a new one.
|
||||
// You need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
message UpdateRequest {
|
||||
// The contents of the object
|
||||
bytes object = 1;
|
||||
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
|
||||
string name = 2;
|
||||
// Who can see this object? "public" or "private", defaults to "private"
|
||||
string visibility = 3;
|
||||
}
|
||||
|
||||
message UpdateResponse {
|
||||
// A public URL to access the object if visibility is "public"
|
||||
string url = 1;
|
||||
}
|
||||
|
||||
// Delete an object
|
||||
message DeleteRequest {
|
||||
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message DeleteResponse {}
|
||||
|
||||
// List the objects in the space
|
||||
message ListRequest {
|
||||
// optional prefix for the name e.g. to return all the objects in the images directory pass images/
|
||||
string prefix = 1;
|
||||
}
|
||||
|
||||
message ListResponse {
|
||||
repeated ListObject objects = 1;
|
||||
}
|
||||
|
||||
message ListObject {
|
||||
string name = 1;
|
||||
// when was this last modified
|
||||
int64 modified = 2;
|
||||
string url = 3;
|
||||
}
|
||||
|
||||
// Retrieve meta information about an object
|
||||
message HeadRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HeadResponse {
|
||||
HeadObject object = 1;
|
||||
}
|
||||
|
||||
message HeadObject {
|
||||
string name = 1;
|
||||
// when was this last modified
|
||||
int64 modified = 2;
|
||||
// when was this created
|
||||
int64 created = 3;
|
||||
// is this public or private
|
||||
string visibility = 4;
|
||||
// URL to access the object if it is public
|
||||
string url = 5;
|
||||
}
|
||||
|
||||
// Read/download the object
|
||||
message ReadRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// Returns the raw object
|
||||
message ReadResponse {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user