mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Comments service (#21)
This commit is contained in:
@@ -5,7 +5,7 @@ MODIFY=Mgithub.com/micro/micro/proto/api/api.proto=github.com/micro/micro/v3/pro
|
||||
.PHONY: proto
|
||||
proto:
|
||||
|
||||
protoc --proto_path=. --micro_out=${MODIFY}:. --go_out=${MODIFY}:. proto/comments/comments.proto
|
||||
protoc --proto_path=. --micro_out=${MODIFY}:. --go_out=${MODIFY}:. proto/comments.proto
|
||||
|
||||
|
||||
.PHONY: build
|
||||
|
||||
@@ -2,15 +2,45 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/dev/model"
|
||||
"github.com/micro/micro/v3/service/store"
|
||||
pb "github.com/micro/services/blog/comments/proto"
|
||||
)
|
||||
|
||||
type Comments struct{}
|
||||
|
||||
// Call is a single request handler called via client.Call or the generated client code
|
||||
func (c *Comments) Save(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
|
||||
logger.Info("Not yet implemented")
|
||||
return nil
|
||||
type Comments struct {
|
||||
comments model.Table
|
||||
idIndex model.Index
|
||||
postIndex model.Index
|
||||
}
|
||||
|
||||
func NewComments() *Comments {
|
||||
postIndex := model.ByEquality("post")
|
||||
postIndex.Order.Type = model.OrderTypeDesc
|
||||
postIndex.Order.FieldName = "created"
|
||||
|
||||
idIndex := model.ByEquality("id")
|
||||
idIndex.Order.Type = model.OrderTypeUnordered
|
||||
|
||||
return &Comments{
|
||||
comments: model.NewTable(store.DefaultStore, "users", model.Indexes(postIndex), nil),
|
||||
postIndex: postIndex,
|
||||
idIndex: idIndex,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Comments) New(ctx context.Context, req *pb.NewRequest, rsp *pb.NewResponse) error {
|
||||
return c.comments.Save(pb.Comment{
|
||||
Id: uuid.New().String(),
|
||||
Post: req.Post,
|
||||
Author: req.Author,
|
||||
Message: req.Message,
|
||||
Created: time.Now().Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Comments) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListResponse) error {
|
||||
return c.comments.List(c.postIndex.ToQuery(req.Post), &rsp.Comments)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func main() {
|
||||
)
|
||||
|
||||
// Register Handler
|
||||
srv.Handle(new(handler.Comments))
|
||||
srv.Handle(handler.NewComments())
|
||||
|
||||
// Run service
|
||||
if err := srv.Run(); err != nil {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: github.com/micro/services/blog/comments/proto/comments.proto
|
||||
// source: proto/comments.proto
|
||||
|
||||
package comments
|
||||
|
||||
@@ -20,106 +20,271 @@ var _ = math.Inf
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type Request struct {
|
||||
// post to comment on
|
||||
PostId string `protobuf:"bytes,1,opt,name=post_id,json=postId,proto3" json:"post_id,omitempty"`
|
||||
// message to leave
|
||||
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
|
||||
type Comment struct {
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Post string `protobuf:"bytes,2,opt,name=post,proto3" json:"post,omitempty"`
|
||||
Author string `protobuf:"bytes,3,opt,name=author,proto3" json:"author,omitempty"`
|
||||
Message string `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"`
|
||||
Created int64 `protobuf:"varint,5,opt,name=created,proto3" json:"created,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Request) Reset() { *m = Request{} }
|
||||
func (m *Request) String() string { return proto.CompactTextString(m) }
|
||||
func (*Request) ProtoMessage() {}
|
||||
func (*Request) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_8266712419156109, []int{0}
|
||||
func (m *Comment) Reset() { *m = Comment{} }
|
||||
func (m *Comment) String() string { return proto.CompactTextString(m) }
|
||||
func (*Comment) ProtoMessage() {}
|
||||
func (*Comment) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_44070930b213c2b7, []int{0}
|
||||
}
|
||||
|
||||
func (m *Request) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Request.Unmarshal(m, b)
|
||||
func (m *Comment) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Comment.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Request.Marshal(b, m, deterministic)
|
||||
func (m *Comment) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Comment.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Request) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Request.Merge(m, src)
|
||||
func (m *Comment) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Comment.Merge(m, src)
|
||||
}
|
||||
func (m *Request) XXX_Size() int {
|
||||
return xxx_messageInfo_Request.Size(m)
|
||||
func (m *Comment) XXX_Size() int {
|
||||
return xxx_messageInfo_Comment.Size(m)
|
||||
}
|
||||
func (m *Request) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Request.DiscardUnknown(m)
|
||||
func (m *Comment) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Comment.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Request proto.InternalMessageInfo
|
||||
var xxx_messageInfo_Comment proto.InternalMessageInfo
|
||||
|
||||
func (m *Request) GetPostId() string {
|
||||
func (m *Comment) GetId() string {
|
||||
if m != nil {
|
||||
return m.PostId
|
||||
return m.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Request) GetMessage() string {
|
||||
func (m *Comment) GetPost() string {
|
||||
if m != nil {
|
||||
return m.Post
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Comment) GetAuthor() string {
|
||||
if m != nil {
|
||||
return m.Author
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Comment) GetMessage() string {
|
||||
if m != nil {
|
||||
return m.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
func (m *Comment) GetCreated() int64 {
|
||||
if m != nil {
|
||||
return m.Created
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type NewRequest struct {
|
||||
// post id
|
||||
Post string `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
|
||||
// message to leave
|
||||
Author string `protobuf:"bytes,2,opt,name=author,proto3" json:"author,omitempty"`
|
||||
Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Response) Reset() { *m = Response{} }
|
||||
func (m *Response) String() string { return proto.CompactTextString(m) }
|
||||
func (*Response) ProtoMessage() {}
|
||||
func (*Response) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_8266712419156109, []int{1}
|
||||
func (m *NewRequest) Reset() { *m = NewRequest{} }
|
||||
func (m *NewRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*NewRequest) ProtoMessage() {}
|
||||
func (*NewRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_44070930b213c2b7, []int{1}
|
||||
}
|
||||
|
||||
func (m *Response) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Response.Unmarshal(m, b)
|
||||
func (m *NewRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_NewRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Response.Marshal(b, m, deterministic)
|
||||
func (m *NewRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_NewRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Response) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Response.Merge(m, src)
|
||||
func (m *NewRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_NewRequest.Merge(m, src)
|
||||
}
|
||||
func (m *Response) XXX_Size() int {
|
||||
return xxx_messageInfo_Response.Size(m)
|
||||
func (m *NewRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_NewRequest.Size(m)
|
||||
}
|
||||
func (m *Response) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Response.DiscardUnknown(m)
|
||||
func (m *NewRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_NewRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Response proto.InternalMessageInfo
|
||||
var xxx_messageInfo_NewRequest proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Request)(nil), "comments.Request")
|
||||
proto.RegisterType((*Response)(nil), "comments.Response")
|
||||
func (m *NewRequest) GetPost() string {
|
||||
if m != nil {
|
||||
return m.Post
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *NewRequest) GetAuthor() string {
|
||||
if m != nil {
|
||||
return m.Author
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *NewRequest) GetMessage() string {
|
||||
if m != nil {
|
||||
return m.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type NewResponse struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *NewResponse) Reset() { *m = NewResponse{} }
|
||||
func (m *NewResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*NewResponse) ProtoMessage() {}
|
||||
func (*NewResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_44070930b213c2b7, []int{2}
|
||||
}
|
||||
|
||||
func (m *NewResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_NewResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *NewResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_NewResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *NewResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_NewResponse.Merge(m, src)
|
||||
}
|
||||
func (m *NewResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_NewResponse.Size(m)
|
||||
}
|
||||
func (m *NewResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_NewResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_NewResponse proto.InternalMessageInfo
|
||||
|
||||
type ListRequest struct {
|
||||
Post string `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ListRequest) Reset() { *m = ListRequest{} }
|
||||
func (m *ListRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ListRequest) ProtoMessage() {}
|
||||
func (*ListRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_44070930b213c2b7, []int{3}
|
||||
}
|
||||
|
||||
func (m *ListRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ListRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *ListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_ListRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *ListRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ListRequest.Merge(m, src)
|
||||
}
|
||||
func (m *ListRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_ListRequest.Size(m)
|
||||
}
|
||||
func (m *ListRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ListRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ListRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *ListRequest) GetPost() string {
|
||||
if m != nil {
|
||||
return m.Post
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ListResponse struct {
|
||||
Comments []*Comment `protobuf:"bytes,1,rep,name=comments,proto3" json:"comments,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ListResponse) Reset() { *m = ListResponse{} }
|
||||
func (m *ListResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ListResponse) ProtoMessage() {}
|
||||
func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_44070930b213c2b7, []int{4}
|
||||
}
|
||||
|
||||
func (m *ListResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ListResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *ListResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ListResponse.Merge(m, src)
|
||||
}
|
||||
func (m *ListResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_ListResponse.Size(m)
|
||||
}
|
||||
func (m *ListResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ListResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ListResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *ListResponse) GetComments() []*Comment {
|
||||
if m != nil {
|
||||
return m.Comments
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("github.com/micro/services/blog/comments/proto/comments.proto", fileDescriptor_8266712419156109)
|
||||
proto.RegisterType((*Comment)(nil), "comments.Comment")
|
||||
proto.RegisterType((*NewRequest)(nil), "comments.NewRequest")
|
||||
proto.RegisterType((*NewResponse)(nil), "comments.NewResponse")
|
||||
proto.RegisterType((*ListRequest)(nil), "comments.ListRequest")
|
||||
proto.RegisterType((*ListResponse)(nil), "comments.ListResponse")
|
||||
}
|
||||
|
||||
var fileDescriptor_8266712419156109 = []byte{
|
||||
// 174 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0xce, 0x31, 0xcf, 0x82, 0x40,
|
||||
0x0c, 0x06, 0xe0, 0x8f, 0x2f, 0x06, 0xb0, 0x9b, 0xb7, 0x48, 0x9c, 0x0c, 0x93, 0x13, 0x4d, 0x74,
|
||||
0x94, 0xcd, 0xc9, 0x15, 0x7f, 0x80, 0x81, 0xa3, 0xc1, 0x4b, 0x3c, 0x8a, 0xf4, 0xe0, 0xf7, 0x1b,
|
||||
0x4f, 0x20, 0x8e, 0x4f, 0x9b, 0xf6, 0x7d, 0x21, 0x6f, 0x8c, 0x7b, 0x0c, 0x55, 0xa6, 0xd9, 0xa2,
|
||||
0x35, 0xba, 0x67, 0x14, 0xea, 0x47, 0xa3, 0x49, 0xb0, 0x7a, 0x72, 0x83, 0x9a, 0xad, 0xa5, 0xd6,
|
||||
0x09, 0x76, 0x3d, 0x3b, 0x5e, 0x98, 0x79, 0xaa, 0x78, 0x76, 0x9a, 0x43, 0x54, 0xd0, 0x6b, 0x20,
|
||||
0x71, 0x6a, 0x0b, 0x51, 0xc7, 0xe2, 0xee, 0xa6, 0x4e, 0x82, 0x7d, 0x70, 0x58, 0x17, 0xe1, 0x87,
|
||||
0xd7, 0x5a, 0x25, 0x10, 0x59, 0x12, 0x29, 0x1b, 0x4a, 0xfe, 0xfd, 0x62, 0x66, 0x0a, 0x10, 0x17,
|
||||
0x24, 0x1d, 0xb7, 0x42, 0xc7, 0x33, 0xc4, 0x97, 0xe9, 0xab, 0x42, 0x58, 0xdd, 0xca, 0x91, 0xd4,
|
||||
0x26, 0x5b, 0x82, 0xa7, 0x94, 0x9d, 0xfa, 0x1d, 0x7d, 0x4f, 0xd3, 0xbf, 0x2a, 0xf4, 0xbd, 0x4e,
|
||||
0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x10, 0x41, 0xc4, 0x9e, 0xd7, 0x00, 0x00, 0x00,
|
||||
func init() {
|
||||
proto.RegisterFile("proto/comments.proto", fileDescriptor_44070930b213c2b7)
|
||||
}
|
||||
|
||||
var fileDescriptor_44070930b213c2b7 = []byte{
|
||||
// 253 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x7c, 0x51, 0xb1, 0x4e, 0xc3, 0x30,
|
||||
0x10, 0x25, 0x71, 0x68, 0xcb, 0x05, 0x90, 0x38, 0x95, 0xca, 0xea, 0x04, 0x9e, 0xba, 0x50, 0xa4,
|
||||
0x82, 0xc4, 0xc4, 0xc4, 0x8a, 0x18, 0xfc, 0x07, 0xa1, 0x3d, 0x41, 0x87, 0xd4, 0x21, 0xe7, 0x0a,
|
||||
0xf5, 0xef, 0x71, 0x1d, 0x3b, 0x0d, 0x11, 0x74, 0xbb, 0xf7, 0xee, 0xdd, 0xbd, 0xf3, 0x33, 0x8c,
|
||||
0xab, 0xda, 0x58, 0x73, 0xbf, 0x34, 0x65, 0x49, 0x1b, 0xcb, 0x73, 0x0f, 0x71, 0x14, 0xb1, 0xda,
|
||||
0xc1, 0xf0, 0xa5, 0xa9, 0xf1, 0x12, 0xd2, 0xf5, 0x4a, 0x26, 0x37, 0xc9, 0xec, 0x4c, 0xbb, 0x0a,
|
||||
0x11, 0xb2, 0xca, 0xb0, 0x95, 0xa9, 0x67, 0x7c, 0x8d, 0x13, 0x18, 0x14, 0x5b, 0xfb, 0x69, 0x6a,
|
||||
0x29, 0x3c, 0x1b, 0x10, 0x4a, 0x18, 0x96, 0xc4, 0x5c, 0x7c, 0x90, 0xcc, 0x7c, 0x23, 0xc2, 0x7d,
|
||||
0x67, 0x59, 0x53, 0x61, 0x69, 0x25, 0x4f, 0x5d, 0x47, 0xe8, 0x08, 0x95, 0x06, 0x78, 0xa3, 0x6f,
|
||||
0x4d, 0x5f, 0x5b, 0x72, 0x9b, 0xa3, 0x5b, 0xf2, 0xa7, 0x5b, 0xfa, 0x9f, 0x9b, 0xf8, 0xe5, 0xa6,
|
||||
0x2e, 0x20, 0xf7, 0x3b, 0xb9, 0x32, 0x1b, 0x26, 0x75, 0x0b, 0xf9, 0xeb, 0x9a, 0xed, 0x11, 0x0f,
|
||||
0xf5, 0x0c, 0xe7, 0x8d, 0xa4, 0x19, 0xc1, 0x3b, 0x68, 0xc3, 0x71, 0x3a, 0x31, 0xcb, 0x17, 0x57,
|
||||
0xf3, 0x36, 0xbd, 0x10, 0x95, 0x6e, 0x25, 0x8b, 0x1d, 0x8c, 0x02, 0xc9, 0xf8, 0x08, 0xc2, 0x99,
|
||||
0xe3, 0xf8, 0xa0, 0x3f, 0xbc, 0x6f, 0x7a, 0xdd, 0x63, 0xc3, 0x85, 0x27, 0xf8, 0x04, 0xd9, 0xfe,
|
||||
0x00, 0xec, 0x08, 0x3a, 0x37, 0x4f, 0x27, 0x7d, 0x3a, 0x0e, 0xbe, 0x0f, 0xfc, 0x5f, 0x3e, 0xfc,
|
||||
0x04, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x0c, 0xe5, 0xcc, 0xe3, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: github.com/micro/services/blog/comments/proto/comments.proto
|
||||
// source: proto/comments.proto
|
||||
|
||||
package comments
|
||||
|
||||
@@ -42,7 +42,8 @@ func NewCommentsEndpoints() []*api.Endpoint {
|
||||
// Client API for Comments service
|
||||
|
||||
type CommentsService interface {
|
||||
Save(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error)
|
||||
New(ctx context.Context, in *NewRequest, opts ...client.CallOption) (*NewResponse, error)
|
||||
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
|
||||
}
|
||||
|
||||
type commentsService struct {
|
||||
@@ -57,9 +58,19 @@ func NewCommentsService(name string, c client.Client) CommentsService {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *commentsService) Save(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) {
|
||||
req := c.c.NewRequest(c.name, "Comments.Save", in)
|
||||
out := new(Response)
|
||||
func (c *commentsService) New(ctx context.Context, in *NewRequest, opts ...client.CallOption) (*NewResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Comments.New", in)
|
||||
out := new(NewResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *commentsService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Comments.List", in)
|
||||
out := new(ListResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -70,12 +81,14 @@ func (c *commentsService) Save(ctx context.Context, in *Request, opts ...client.
|
||||
// Server API for Comments service
|
||||
|
||||
type CommentsHandler interface {
|
||||
Save(context.Context, *Request, *Response) error
|
||||
New(context.Context, *NewRequest, *NewResponse) error
|
||||
List(context.Context, *ListRequest, *ListResponse) error
|
||||
}
|
||||
|
||||
func RegisterCommentsHandler(s server.Server, hdlr CommentsHandler, opts ...server.HandlerOption) error {
|
||||
type comments interface {
|
||||
Save(ctx context.Context, in *Request, out *Response) error
|
||||
New(ctx context.Context, in *NewRequest, out *NewResponse) error
|
||||
List(ctx context.Context, in *ListRequest, out *ListResponse) error
|
||||
}
|
||||
type Comments struct {
|
||||
comments
|
||||
@@ -88,6 +101,10 @@ type commentsHandler struct {
|
||||
CommentsHandler
|
||||
}
|
||||
|
||||
func (h *commentsHandler) Save(ctx context.Context, in *Request, out *Response) error {
|
||||
return h.CommentsHandler.Save(ctx, in, out)
|
||||
func (h *commentsHandler) New(ctx context.Context, in *NewRequest, out *NewResponse) error {
|
||||
return h.CommentsHandler.New(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *commentsHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error {
|
||||
return h.CommentsHandler.List(ctx, in, out)
|
||||
}
|
||||
|
||||
@@ -3,15 +3,32 @@ syntax = "proto3";
|
||||
package comments;
|
||||
|
||||
service Comments {
|
||||
rpc Save(Request) returns (Response) {}
|
||||
rpc New(NewRequest) returns (NewResponse) {}
|
||||
rpc List(ListRequest) returns (ListResponse) {}
|
||||
}
|
||||
|
||||
message Request {
|
||||
// post to comment on
|
||||
string post_id = 1;
|
||||
message Comment {
|
||||
string id = 1;
|
||||
string post = 2;
|
||||
string author = 3;
|
||||
string message = 4;
|
||||
int64 created = 5;
|
||||
}
|
||||
|
||||
message NewRequest {
|
||||
// post id
|
||||
string post = 1;
|
||||
// message to leave
|
||||
string message = 2;
|
||||
|
||||
string author = 2;
|
||||
string message = 3;
|
||||
}
|
||||
|
||||
message Response {}
|
||||
message NewResponse {}
|
||||
|
||||
message ListRequest{
|
||||
string post = 1;
|
||||
}
|
||||
|
||||
message ListResponse{
|
||||
repeated Comment comments = 1;
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -7,7 +7,7 @@ require (
|
||||
github.com/golang/protobuf v1.4.3
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/gosimple/slug v1.9.0
|
||||
github.com/micro/dev v0.0.0-20201026103917-a7b0e7877fa5
|
||||
github.com/micro/dev v0.0.0-20201030123519-9dee6b61fdc2
|
||||
github.com/micro/go-micro/v2 v2.9.1 // indirect
|
||||
github.com/micro/micro/v3 v3.0.0-beta.7
|
||||
github.com/miekg/dns v1.1.31 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -334,6 +334,8 @@ github.com/micro/dev v0.0.0-20201023140212-49030ae8a31f h1:V9kC0gSrAUgXT3o5gMzQ3
|
||||
github.com/micro/dev v0.0.0-20201023140212-49030ae8a31f/go.mod h1:j/8E+ezN/ij7a9BXBHMKmLayFfUW1O4h/Owdv67B0X0=
|
||||
github.com/micro/dev v0.0.0-20201026103917-a7b0e7877fa5 h1:TKVhBhhLeJyWihKdg7bDd7J+h6MWx2Y0niEMmTfyOOw=
|
||||
github.com/micro/dev v0.0.0-20201026103917-a7b0e7877fa5/go.mod h1:j/8E+ezN/ij7a9BXBHMKmLayFfUW1O4h/Owdv67B0X0=
|
||||
github.com/micro/dev v0.0.0-20201030123519-9dee6b61fdc2 h1:AFnDvzVGaoby5itR/Ma85lajomD2wOgtdbLmXhHeTqY=
|
||||
github.com/micro/dev v0.0.0-20201030123519-9dee6b61fdc2/go.mod h1:j/8E+ezN/ij7a9BXBHMKmLayFfUW1O4h/Owdv67B0X0=
|
||||
github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E=
|
||||
github.com/micro/go-micro/v2 v2.9.1 h1:+S9koIrNWARjpP6k2TZ7kt0uC9zUJtNXzIdZTZRms7Q=
|
||||
github.com/micro/go-micro/v2 v2.9.1/go.mod h1:x55ZM3Puy0FyvvkR3e0ha0xsE9DFwfPSUMWAIbFY0SY=
|
||||
|
||||
Reference in New Issue
Block a user