mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
add space aapi
This commit is contained in:
2
space/.gitignore
vendored
Normal file
2
space/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
nft
|
||||
3
space/Dockerfile
Normal file
3
space/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM alpine
|
||||
ADD space /space
|
||||
ENTRYPOINT [ "/space" ]
|
||||
28
space/Makefile
Normal file
28
space/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
GOPATH:=$(shell go env GOPATH)
|
||||
.PHONY: init
|
||||
init:
|
||||
go get -u github.com/golang/protobuf/proto
|
||||
go get -u github.com/golang/protobuf/protoc-gen-go
|
||||
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
|
||||
go get github.com/micro/micro/v3/cmd/protoc-gen-openapi
|
||||
|
||||
.PHONY: api
|
||||
api:
|
||||
protoc --openapi_out=. --proto_path=. proto/space.proto
|
||||
|
||||
.PHONY: proto
|
||||
proto:
|
||||
protoc --proto_path=. --micro_out=. --go_out=:. proto/space.proto
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
go build -o space *.go
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -v ./... -cover
|
||||
|
||||
.PHONY: docker
|
||||
docker:
|
||||
docker build . -t space:latest
|
||||
7
space/README.md
Normal file
7
space/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Infinite cloud storage
|
||||
|
||||
# NFT Service
|
||||
|
||||
Space for simple object storage. Put anything in the cloud
|
||||
forever. Backed by S3 compatible storage API.
|
||||
|
||||
14
space/examples.json
Normal file
14
space/examples.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"vote": [
|
||||
{
|
||||
"title": "Vote for the API",
|
||||
"run_check": false,
|
||||
"request": {
|
||||
"message": "Launch it!"
|
||||
},
|
||||
"response": {
|
||||
"message": "Thanks for the vote!"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
space/generate.go
Normal file
2
space/generate.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package main
|
||||
//go:generate make proto
|
||||
50
space/handler/space.go
Normal file
50
space/handler/space.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/micro/services/pkg/tenant"
|
||||
"github.com/micro/micro/v3/service/store"
|
||||
pb "github.com/micro/services/space/proto"
|
||||
)
|
||||
|
||||
type Space struct{}
|
||||
|
||||
var (
|
||||
mtx sync.RWMutex
|
||||
|
||||
voteKey = "votes/"
|
||||
)
|
||||
|
||||
type Vote struct {
|
||||
Id string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
VotedAt time.Time `json:"voted_at"`
|
||||
}
|
||||
|
||||
func (n *Space) Vote(ctx context.Context, req *pb.VoteRequest, rsp *pb.VoteResponse) error {
|
||||
mtx.Lock()
|
||||
defer mtx.Unlock()
|
||||
|
||||
id, ok := tenant.FromContext(ctx)
|
||||
if !ok {
|
||||
id = "micro"
|
||||
}
|
||||
|
||||
rec := store.NewRecord(voteKey + id, &Vote{
|
||||
Id: id,
|
||||
Message: req.Message,
|
||||
VotedAt: time.Now(),
|
||||
})
|
||||
|
||||
// we don't need to check the error
|
||||
store.Write(rec)
|
||||
|
||||
rsp.Message = "Thanks for the vote!"
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
24
space/main.go
Normal file
24
space/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/micro/services/space/handler"
|
||||
pb "github.com/micro/services/space/proto"
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create service
|
||||
srv := service.New(
|
||||
service.Name("space"),
|
||||
service.Version("latest"),
|
||||
)
|
||||
|
||||
// Register handler
|
||||
pb.RegisterSpaceHandler(srv.Server(), new(handler.Space))
|
||||
|
||||
// Run service
|
||||
if err := srv.Run(); err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
}
|
||||
1
space/micro.mu
Normal file
1
space/micro.mu
Normal file
@@ -0,0 +1 @@
|
||||
service space
|
||||
213
space/proto/space.pb.go
Normal file
213
space/proto/space.pb.go
Normal file
@@ -0,0 +1,213 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.15.6
|
||||
// source: proto/space.proto
|
||||
|
||||
package space
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
// Vote to have the NFT api launched faster!
|
||||
type VoteRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// optional message
|
||||
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *VoteRequest) Reset() {
|
||||
*x = VoteRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_space_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *VoteRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*VoteRequest) ProtoMessage() {}
|
||||
|
||||
func (x *VoteRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_space_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 VoteRequest.ProtoReflect.Descriptor instead.
|
||||
func (*VoteRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_space_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *VoteRequest) GetMessage() string {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type VoteResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// response message
|
||||
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *VoteResponse) Reset() {
|
||||
*x = VoteResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_space_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *VoteResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*VoteResponse) ProtoMessage() {}
|
||||
|
||||
func (x *VoteResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_space_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 VoteResponse.ProtoReflect.Descriptor instead.
|
||||
func (*VoteResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_space_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *VoteResponse) GetMessage() string {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_proto_space_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_space_proto_rawDesc = []byte{
|
||||
0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6e, 0x66, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x12, 0x03, 0x6e, 0x66, 0x74, 0x22, 0x27, 0x0a, 0x0b, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 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, 0x22,
|
||||
0x28, 0x0a, 0x0c, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x34, 0x0a, 0x03, 0x4e, 0x66, 0x74,
|
||||
0x12, 0x2d, 0x0a, 0x04, 0x56, 0x6f, 0x74, 0x65, 0x12, 0x10, 0x2e, 0x6e, 0x66, 0x74, 0x2e, 0x56,
|
||||
0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6e, 0x66, 0x74,
|
||||
0x2e, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42,
|
||||
0x0d, 0x5a, 0x0b, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6e, 0x66, 0x74, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_proto_space_proto_rawDescOnce sync.Once
|
||||
file_proto_space_proto_rawDescData = file_proto_space_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_proto_space_proto_rawDescGZIP() []byte {
|
||||
file_proto_space_proto_rawDescOnce.Do(func() {
|
||||
file_proto_space_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_space_proto_rawDescData)
|
||||
})
|
||||
return file_proto_space_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_space_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_proto_space_proto_goTypes = []interface{}{
|
||||
(*VoteRequest)(nil), // 0: space.VoteRequest
|
||||
(*VoteResponse)(nil), // 1: space.VoteResponse
|
||||
}
|
||||
var file_proto_space_proto_depIdxs = []int32{
|
||||
0, // 0: space.Space.Vote:input_type -> space.VoteRequest
|
||||
1, // 1: space.Space.Vote:output_type -> space.VoteResponse
|
||||
1, // [1:2] is the sub-list for method output_type
|
||||
0, // [0:1] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_space_proto_init() }
|
||||
func file_proto_space_proto_init() {
|
||||
if File_proto_space_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_proto_space_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*VoteRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_space_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*VoteResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_space_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_proto_space_proto_goTypes,
|
||||
DependencyIndexes: file_proto_space_proto_depIdxs,
|
||||
MessageInfos: file_proto_space_proto_msgTypes,
|
||||
}.Build()
|
||||
File_proto_space_proto = out.File
|
||||
file_proto_space_proto_rawDesc = nil
|
||||
file_proto_space_proto_goTypes = nil
|
||||
file_proto_space_proto_depIdxs = nil
|
||||
}
|
||||
93
space/proto/space.pb.micro.go
Normal file
93
space/proto/space.pb.micro.go
Normal file
@@ -0,0 +1,93 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/space.proto
|
||||
|
||||
package space
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/micro/micro/v3/service/api"
|
||||
client "github.com/micro/micro/v3/service/client"
|
||||
server "github.com/micro/micro/v3/service/server"
|
||||
)
|
||||
|
||||
// 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
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ api.Endpoint
|
||||
var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for Space service
|
||||
|
||||
func NewSpaceEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Space service
|
||||
|
||||
type SpaceService interface {
|
||||
Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error)
|
||||
}
|
||||
|
||||
type spaceService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewSpaceService(name string, c client.Client) SpaceService {
|
||||
return &spaceService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Space service
|
||||
|
||||
type SpaceHandler interface {
|
||||
Vote(context.Context, *VoteRequest, *VoteResponse) error
|
||||
}
|
||||
|
||||
func RegisterSpaceHandler(s server.Server, hdlr SpaceHandler, opts ...server.HandlerOption) error {
|
||||
type space interface {
|
||||
Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error
|
||||
}
|
||||
type Space struct {
|
||||
space
|
||||
}
|
||||
h := &spaceHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Space{h}, opts...))
|
||||
}
|
||||
|
||||
type spaceHandler struct {
|
||||
SpaceHandler
|
||||
}
|
||||
|
||||
func (h *spaceHandler) Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error {
|
||||
return h.SpaceHandler.Vote(ctx, in, out)
|
||||
}
|
||||
20
space/proto/space.proto
Normal file
20
space/proto/space.proto
Normal file
@@ -0,0 +1,20 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package space;
|
||||
|
||||
option go_package = "./proto;space";
|
||||
|
||||
service Space {
|
||||
rpc Vote(VoteRequest) returns (VoteResponse) {}
|
||||
}
|
||||
|
||||
// Vote to have the Space api launched faster!
|
||||
message VoteRequest {
|
||||
// optional message
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message VoteResponse {
|
||||
// response message
|
||||
string message = 2;
|
||||
}
|
||||
6
space/publicapi.json
Normal file
6
space/publicapi.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "space",
|
||||
"icon": "🪙",
|
||||
"category": "coming soon",
|
||||
"display_name": "NFT (Coming Soon)"
|
||||
}
|
||||
Reference in New Issue
Block a user