mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-12 11:15:12 +00:00
add vote handler to app
This commit is contained in:
@@ -16,5 +16,17 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"vote": [
|
||||
{
|
||||
"title": "Vote for the API",
|
||||
"run_check": false,
|
||||
"request": {
|
||||
"message": "Launch it!"
|
||||
},
|
||||
"response": {
|
||||
"message": "Thanks for the vote!"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
44
app/handler/vote.go
Normal file
44
app/handler/vote.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/micro/services/pkg/tenant"
|
||||
"github.com/micro/micro/v3/service/store"
|
||||
pb "github.com/micro/services/app/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
voteKey = "votes/"
|
||||
)
|
||||
|
||||
type Vote struct {
|
||||
Id string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
VotedAt time.Time `json:"voted_at"`
|
||||
}
|
||||
|
||||
func (n *App) 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
|
||||
}
|
||||
@@ -20,6 +20,103 @@ const (
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// Vote to have the App 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_app_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_app_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_app_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_app_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_app_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_app_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *VoteResponse) GetMessage() string {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Reservation struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -40,7 +137,7 @@ type Reservation struct {
|
||||
func (x *Reservation) Reset() {
|
||||
*x = Reservation{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_app_proto_msgTypes[0]
|
||||
mi := &file_proto_app_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -53,7 +150,7 @@ func (x *Reservation) String() string {
|
||||
func (*Reservation) ProtoMessage() {}
|
||||
|
||||
func (x *Reservation) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_app_proto_msgTypes[0]
|
||||
mi := &file_proto_app_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -66,7 +163,7 @@ func (x *Reservation) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use Reservation.ProtoReflect.Descriptor instead.
|
||||
func (*Reservation) Descriptor() ([]byte, []int) {
|
||||
return file_proto_app_proto_rawDescGZIP(), []int{0}
|
||||
return file_proto_app_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *Reservation) GetName() string {
|
||||
@@ -117,7 +214,7 @@ type ReserveRequest struct {
|
||||
func (x *ReserveRequest) Reset() {
|
||||
*x = ReserveRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_app_proto_msgTypes[1]
|
||||
mi := &file_proto_app_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -130,7 +227,7 @@ func (x *ReserveRequest) String() string {
|
||||
func (*ReserveRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ReserveRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_app_proto_msgTypes[1]
|
||||
mi := &file_proto_app_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -143,7 +240,7 @@ func (x *ReserveRequest) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use ReserveRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ReserveRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_app_proto_rawDescGZIP(), []int{1}
|
||||
return file_proto_app_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *ReserveRequest) GetName() string {
|
||||
@@ -164,7 +261,7 @@ type ReserveResponse struct {
|
||||
func (x *ReserveResponse) Reset() {
|
||||
*x = ReserveResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_app_proto_msgTypes[2]
|
||||
mi := &file_proto_app_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -177,7 +274,7 @@ func (x *ReserveResponse) String() string {
|
||||
func (*ReserveResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ReserveResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_app_proto_msgTypes[2]
|
||||
mi := &file_proto_app_proto_msgTypes[4]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -190,7 +287,7 @@ func (x *ReserveResponse) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use ReserveResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ReserveResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_app_proto_rawDescGZIP(), []int{2}
|
||||
return file_proto_app_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ReserveResponse) GetReservation() *Reservation {
|
||||
@@ -204,27 +301,35 @@ var File_proto_app_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_app_proto_rawDesc = []byte{
|
||||
0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x70, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x12, 0x03, 0x61, 0x70, 0x70, 0x22, 0x81, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x73, 0x65, 0x72,
|
||||
0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77,
|
||||
0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72,
|
||||
0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
||||
0x12, 0x18, 0x0a, 0x07, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x07, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x22, 0x24, 0x0a, 0x0e, 0x52, 0x65,
|
||||
0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x22, 0x45, 0x0a, 0x0f, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x0b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x52,
|
||||
0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x65,
|
||||
0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x3d, 0x0a, 0x03, 0x41, 0x70, 0x70, 0x12, 0x36,
|
||||
0x0a, 0x07, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x12, 0x13, 0x2e, 0x61, 0x70, 0x70, 0x2e,
|
||||
0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14,
|
||||
0x2e, 0x61, 0x70, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x3b, 0x61, 0x70, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x6f, 0x12, 0x03, 0x61, 0x70, 0x70, 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, 0x22, 0x81, 0x01, 0x0a, 0x0b, 0x52, 0x65,
|
||||
0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d,
|
||||
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a,
|
||||
0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77,
|
||||
0x6e, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65,
|
||||
0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61,
|
||||
0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x18, 0x05,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x22, 0x24, 0x0a,
|
||||
0x0e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e,
|
||||
0x61, 0x6d, 0x65, 0x22, 0x45, 0x0a, 0x0f, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x0b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76,
|
||||
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70,
|
||||
0x70, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72,
|
||||
0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x6c, 0x0a, 0x03, 0x41, 0x70,
|
||||
0x70, 0x12, 0x36, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x12, 0x13, 0x2e, 0x61,
|
||||
0x70, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x1a, 0x14, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x04, 0x56, 0x6f, 0x74,
|
||||
0x65, 0x12, 0x10, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x61, 0x70, 0x70, 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, 0x61, 0x70, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -239,18 +344,22 @@ func file_proto_app_proto_rawDescGZIP() []byte {
|
||||
return file_proto_app_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_app_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_proto_app_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||
var file_proto_app_proto_goTypes = []interface{}{
|
||||
(*Reservation)(nil), // 0: app.Reservation
|
||||
(*ReserveRequest)(nil), // 1: app.ReserveRequest
|
||||
(*ReserveResponse)(nil), // 2: app.ReserveResponse
|
||||
(*VoteRequest)(nil), // 0: app.VoteRequest
|
||||
(*VoteResponse)(nil), // 1: app.VoteResponse
|
||||
(*Reservation)(nil), // 2: app.Reservation
|
||||
(*ReserveRequest)(nil), // 3: app.ReserveRequest
|
||||
(*ReserveResponse)(nil), // 4: app.ReserveResponse
|
||||
}
|
||||
var file_proto_app_proto_depIdxs = []int32{
|
||||
0, // 0: app.ReserveResponse.reservation:type_name -> app.Reservation
|
||||
1, // 1: app.App.Reserve:input_type -> app.ReserveRequest
|
||||
2, // 2: app.App.Reserve:output_type -> app.ReserveResponse
|
||||
2, // [2:3] is the sub-list for method output_type
|
||||
1, // [1:2] is the sub-list for method input_type
|
||||
2, // 0: app.ReserveResponse.reservation:type_name -> app.Reservation
|
||||
3, // 1: app.App.Reserve:input_type -> app.ReserveRequest
|
||||
0, // 2: app.App.Vote:input_type -> app.VoteRequest
|
||||
4, // 3: app.App.Reserve:output_type -> app.ReserveResponse
|
||||
1, // 4: app.App.Vote:output_type -> app.VoteResponse
|
||||
3, // [3:5] is the sub-list for method output_type
|
||||
1, // [1:3] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
@@ -263,7 +372,7 @@ func file_proto_app_proto_init() {
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_proto_app_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Reservation); i {
|
||||
switch v := v.(*VoteRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -275,7 +384,7 @@ func file_proto_app_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_app_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ReserveRequest); i {
|
||||
switch v := v.(*VoteResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -287,6 +396,30 @@ func file_proto_app_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_app_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Reservation); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_app_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ReserveRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_app_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ReserveResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -305,7 +438,7 @@ func file_proto_app_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_app_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 3,
|
||||
NumMessages: 5,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -43,6 +43,7 @@ func NewAppEndpoints() []*api.Endpoint {
|
||||
|
||||
type AppService interface {
|
||||
Reserve(ctx context.Context, in *ReserveRequest, opts ...client.CallOption) (*ReserveResponse, error)
|
||||
Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error)
|
||||
}
|
||||
|
||||
type appService struct {
|
||||
@@ -67,15 +68,27 @@ func (c *appService) Reserve(ctx context.Context, in *ReserveRequest, opts ...cl
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *appService) Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "App.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 App service
|
||||
|
||||
type AppHandler interface {
|
||||
Reserve(context.Context, *ReserveRequest, *ReserveResponse) error
|
||||
Vote(context.Context, *VoteRequest, *VoteResponse) error
|
||||
}
|
||||
|
||||
func RegisterAppHandler(s server.Server, hdlr AppHandler, opts ...server.HandlerOption) error {
|
||||
type app interface {
|
||||
Reserve(ctx context.Context, in *ReserveRequest, out *ReserveResponse) error
|
||||
Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error
|
||||
}
|
||||
type App struct {
|
||||
app
|
||||
@@ -91,3 +104,7 @@ type appHandler struct {
|
||||
func (h *appHandler) Reserve(ctx context.Context, in *ReserveRequest, out *ReserveResponse) error {
|
||||
return h.AppHandler.Reserve(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *appHandler) Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error {
|
||||
return h.AppHandler.Vote(ctx, in, out)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,18 @@ option go_package = "./proto;app";
|
||||
|
||||
service App {
|
||||
rpc Reserve(ReserveRequest) returns (ReserveResponse) {}
|
||||
rpc Vote(VoteRequest) returns (VoteResponse) {}
|
||||
}
|
||||
|
||||
// Vote to have the App api launched faster!
|
||||
message VoteRequest {
|
||||
// optional message
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message VoteResponse {
|
||||
// response message
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message Reservation {
|
||||
|
||||
Reference in New Issue
Block a user