Blog changes + tests (#4)

* Blog changes + tests

* Fix build

* Fix

* Add back step

* Fix logger

* Fix test

* Typo

* Better test

* Changes to tests

* Update micro

* Fixing all them things

* Fixing even more things :))

* Bump micro

* Fix posts and tags by following micro changes

* Trying to pin workflow to correct micro version

* huh

* Bump go micro

* Add etcd replace

* Changing a bunch of things

* Denormalize to fix bug

* Fixes
This commit is contained in:
Janos Dobronszki
2020-10-15 15:09:59 +02:00
committed by GitHub
parent 4eb8479f9f
commit 6e8d7f4248
30 changed files with 1203 additions and 1449 deletions

View File

@@ -5,7 +5,7 @@ MODIFY=Mgithub.com/micro/go-micro/api/proto/api.proto=github.com/micro/go-micro/
.PHONY: proto
proto:
protoc --proto_path=. --micro_out=${MODIFY}:. --go_out=${MODIFY}:. proto/post/post.proto
protoc --proto_path=. --micro_out=${MODIFY}:. --go_out=${MODIFY}:. proto/posts/posts.proto
.PHONY: build

View File

@@ -8,7 +8,6 @@ import (
"time"
"github.com/micro/go-micro/v3/errors"
gostore "github.com/micro/go-micro/v3/store"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
@@ -32,7 +31,7 @@ type Post struct {
Content string `json:"content"`
CreateTimestamp int64 `json:"create_timestamp"`
UpdateTimestamp int64 `json:"update_timestamp"`
TagNames []string `json:"tagNames"`
Tags []string `json:"tags"`
}
type Posts struct {
@@ -40,23 +39,23 @@ type Posts struct {
}
func (p *Posts) Save(ctx context.Context, req *posts.SaveRequest, rsp *posts.SaveResponse) error {
if len(req.Post.Id) == 0 || len(req.Post.Title) == 0 || len(req.Post.Content) == 0 {
if len(req.Id) == 0 || len(req.Title) == 0 || len(req.Content) == 0 {
return errors.BadRequest("posts.save.input-check", "Id, title or content is missing")
}
// read by post
records, err := store.Read(fmt.Sprintf("%v:%v", idPrefix, req.Post.Id))
if err != nil && err != gostore.ErrNotFound {
records, err := store.Read(fmt.Sprintf("%v:%v", idPrefix, req.Id))
if err != nil && err != store.ErrNotFound {
return errors.InternalServerError("posts.save.store-id-read", "Failed to read post by id: %v", err.Error())
}
postSlug := slug.Make(req.Post.Title)
postSlug := slug.Make(req.Title)
// If no existing record is found, create a new one
if len(records) == 0 {
post := &Post{
ID: req.Post.Id,
Title: req.Post.Title,
Content: req.Post.Content,
TagNames: req.Post.TagNames,
ID: req.Id,
Title: req.Title,
Content: req.Content,
Tags: req.Tags,
Slug: postSlug,
CreateTimestamp: time.Now().Unix(),
}
@@ -73,18 +72,18 @@ func (p *Posts) Save(ctx context.Context, req *posts.SaveRequest, rsp *posts.Sav
return errors.InternalServerError("posts.save.unmarshal", "Failed to unmarshal old post: %v", err.Error())
}
post := &Post{
ID: req.Post.Id,
Title: req.Post.Title,
Content: req.Post.Content,
ID: req.Id,
Title: req.Title,
Content: req.Content,
Slug: postSlug,
TagNames: req.Post.TagNames,
Tags: req.Tags,
CreateTimestamp: oldPost.CreateTimestamp,
UpdateTimestamp: time.Now().Unix(),
}
// Check if slug exists
recordsBySlug, err := store.Read(fmt.Sprintf("%v:%v", slugPrefix, postSlug))
if err != nil && err != gostore.ErrNotFound {
if err != nil && err != store.ErrNotFound {
return errors.InternalServerError("posts.save.store-read", "Failed to read post by slug: %v", err.Error())
}
otherSlugPost := &Post{}
@@ -105,7 +104,7 @@ func (p *Posts) savePost(ctx context.Context, oldPost, post *Post) error {
return err
}
err = store.Write(&gostore.Record{
err = store.Write(&store.Record{
Key: fmt.Sprintf("%v:%v", idPrefix, post.ID),
Value: bytes,
})
@@ -119,14 +118,14 @@ func (p *Posts) savePost(ctx context.Context, oldPost, post *Post) error {
return err
}
}
err = store.Write(&gostore.Record{
err = store.Write(&store.Record{
Key: fmt.Sprintf("%v:%v", slugPrefix, post.Slug),
Value: bytes,
})
if err != nil {
return err
}
err = store.Write(&gostore.Record{
err = store.Write(&store.Record{
Key: fmt.Sprintf("%v:%v", timeStampPrefix, math.MaxInt64-post.CreateTimestamp),
Value: bytes,
})
@@ -134,8 +133,8 @@ func (p *Posts) savePost(ctx context.Context, oldPost, post *Post) error {
return err
}
if oldPost == nil {
for _, tagName := range post.TagNames {
_, err := p.Tags.IncreaseCount(ctx, &tags.IncreaseCountRequest{
for _, tagName := range post.Tags {
_, err := p.Tags.Add(ctx, &tags.AddRequest{
ParentID: post.ID,
Type: tagType,
Title: tagName,
@@ -146,7 +145,7 @@ func (p *Posts) savePost(ctx context.Context, oldPost, post *Post) error {
}
return nil
}
return p.diffTags(ctx, post.ID, oldPost.TagNames, post.TagNames)
return p.diffTags(ctx, post.ID, oldPost.Tags, post.Tags)
}
func (p *Posts) diffTags(ctx context.Context, parentID string, oldTagNames, newTagNames []string) error {
@@ -161,7 +160,7 @@ func (p *Posts) diffTags(ctx context.Context, parentID string, oldTagNames, newT
for i := range oldTags {
_, stillThere := newTags[i]
if !stillThere {
_, err := p.Tags.DecreaseCount(ctx, &tags.DecreaseCountRequest{
_, err := p.Tags.Remove(ctx, &tags.RemoveRequest{
ParentID: parentID,
Type: tagType,
Title: i,
@@ -174,13 +173,13 @@ func (p *Posts) diffTags(ctx context.Context, parentID string, oldTagNames, newT
for i := range newTags {
_, newlyAdded := oldTags[i]
if newlyAdded {
_, err := p.Tags.IncreaseCount(ctx, &tags.IncreaseCountRequest{
_, err := p.Tags.Add(ctx, &tags.AddRequest{
ParentID: parentID,
Type: tagType,
Title: i,
})
if err != nil {
logger.Errorf("Error increasing count for tag '%v' with type '%v' for parent '%v'", i, tagType, parentID)
logger.Errorf("Error increasing count for tag '%v' with type '%v' for parent '%v': %v", i, tagType, parentID, err)
}
}
}
@@ -188,7 +187,7 @@ func (p *Posts) diffTags(ctx context.Context, parentID string, oldTagNames, newT
}
func (p *Posts) Query(ctx context.Context, req *pb.QueryRequest, rsp *pb.QueryResponse) error {
var records []*gostore.Record
var records []*store.Record
var err error
if len(req.Slug) > 0 {
key := fmt.Sprintf("%v:%v", slugPrefix, req.Slug)
@@ -218,11 +217,11 @@ func (p *Posts) Query(ctx context.Context, req *pb.QueryRequest, rsp *pb.QueryRe
return errors.InternalServerError("posts.save.unmarshal", "Failed to unmarshal old post: %v", err.Error())
}
rsp.Posts[i] = &pb.Post{
Id: postRecord.ID,
Title: postRecord.Title,
Slug: postRecord.Slug,
Content: postRecord.Content,
TagNames: postRecord.TagNames,
Id: postRecord.ID,
Title: postRecord.Title,
Slug: postRecord.Slug,
Content: postRecord.Content,
Tags: postRecord.Tags,
}
}
return nil
@@ -231,7 +230,7 @@ func (p *Posts) Query(ctx context.Context, req *pb.QueryRequest, rsp *pb.QueryRe
func (p *Posts) Delete(ctx context.Context, req *pb.DeleteRequest, rsp *pb.DeleteResponse) error {
logger.Info("Received Post.Delete request")
records, err := store.Read(fmt.Sprintf("%v:%v", idPrefix, req.Id))
if err != nil && err != gostore.ErrNotFound {
if err != nil && err != store.ErrNotFound {
return err
}
if len(records) == 0 {

View File

@@ -1,5 +1,5 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: blog/posts/proto/posts/post.proto
// source: proto/posts/posts.proto
package posts
@@ -25,8 +25,10 @@ type Post struct {
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
Slug string `protobuf:"bytes,3,opt,name=slug,proto3" json:"slug,omitempty"`
Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
TagNames []string `protobuf:"bytes,6,rep,name=tagNames,proto3" json:"tagNames,omitempty"`
Created int64 `protobuf:"varint,5,opt,name=created,proto3" json:"created,omitempty"`
Updated int64 `protobuf:"varint,6,opt,name=updated,proto3" json:"updated,omitempty"`
Author string `protobuf:"bytes,7,opt,name=author,proto3" json:"author,omitempty"`
Tags []string `protobuf:"bytes,8,rep,name=tags,proto3" json:"tags,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -36,7 +38,7 @@ func (m *Post) Reset() { *m = Post{} }
func (m *Post) String() string { return proto.CompactTextString(m) }
func (*Post) ProtoMessage() {}
func (*Post) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{0}
return fileDescriptor_a1e4efc789192621, []int{0}
}
func (m *Post) XXX_Unmarshal(b []byte) error {
@@ -85,16 +87,30 @@ func (m *Post) GetContent() string {
return ""
}
func (m *Post) GetTimestamp() int64 {
func (m *Post) GetCreated() int64 {
if m != nil {
return m.Timestamp
return m.Created
}
return 0
}
func (m *Post) GetTagNames() []string {
func (m *Post) GetUpdated() int64 {
if m != nil {
return m.TagNames
return m.Updated
}
return 0
}
func (m *Post) GetAuthor() string {
if m != nil {
return m.Author
}
return ""
}
func (m *Post) GetTags() []string {
if m != nil {
return m.Tags
}
return nil
}
@@ -112,7 +128,7 @@ func (m *QueryRequest) Reset() { *m = QueryRequest{} }
func (m *QueryRequest) String() string { return proto.CompactTextString(m) }
func (*QueryRequest) ProtoMessage() {}
func (*QueryRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{1}
return fileDescriptor_a1e4efc789192621, []int{1}
}
func (m *QueryRequest) XXX_Unmarshal(b []byte) error {
@@ -165,7 +181,7 @@ func (m *QueryResponse) Reset() { *m = QueryResponse{} }
func (m *QueryResponse) String() string { return proto.CompactTextString(m) }
func (*QueryResponse) ProtoMessage() {}
func (*QueryResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{2}
return fileDescriptor_a1e4efc789192621, []int{2}
}
func (m *QueryResponse) XXX_Unmarshal(b []byte) error {
@@ -194,7 +210,12 @@ func (m *QueryResponse) GetPosts() []*Post {
}
type SaveRequest struct {
Post *Post `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
Slug string `protobuf:"bytes,3,opt,name=slug,proto3" json:"slug,omitempty"`
Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Tags []string `protobuf:"bytes,6,rep,name=tags,proto3" json:"tags,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -204,7 +225,7 @@ func (m *SaveRequest) Reset() { *m = SaveRequest{} }
func (m *SaveRequest) String() string { return proto.CompactTextString(m) }
func (*SaveRequest) ProtoMessage() {}
func (*SaveRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{3}
return fileDescriptor_a1e4efc789192621, []int{3}
}
func (m *SaveRequest) XXX_Unmarshal(b []byte) error {
@@ -225,15 +246,50 @@ func (m *SaveRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_SaveRequest proto.InternalMessageInfo
func (m *SaveRequest) GetPost() *Post {
func (m *SaveRequest) GetId() string {
if m != nil {
return m.Post
return m.Id
}
return ""
}
func (m *SaveRequest) GetTitle() string {
if m != nil {
return m.Title
}
return ""
}
func (m *SaveRequest) GetSlug() string {
if m != nil {
return m.Slug
}
return ""
}
func (m *SaveRequest) GetContent() string {
if m != nil {
return m.Content
}
return ""
}
func (m *SaveRequest) GetTimestamp() int64 {
if m != nil {
return m.Timestamp
}
return 0
}
func (m *SaveRequest) GetTags() []string {
if m != nil {
return m.Tags
}
return nil
}
type SaveResponse struct {
Post *Post `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -243,7 +299,7 @@ func (m *SaveResponse) Reset() { *m = SaveResponse{} }
func (m *SaveResponse) String() string { return proto.CompactTextString(m) }
func (*SaveResponse) ProtoMessage() {}
func (*SaveResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{4}
return fileDescriptor_a1e4efc789192621, []int{4}
}
func (m *SaveResponse) XXX_Unmarshal(b []byte) error {
@@ -264,11 +320,11 @@ func (m *SaveResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_SaveResponse proto.InternalMessageInfo
func (m *SaveResponse) GetPost() *Post {
func (m *SaveResponse) GetId() string {
if m != nil {
return m.Post
return m.Id
}
return nil
return ""
}
type DeleteRequest struct {
@@ -282,7 +338,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} }
func (m *DeleteRequest) String() string { return proto.CompactTextString(m) }
func (*DeleteRequest) ProtoMessage() {}
func (*DeleteRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{5}
return fileDescriptor_a1e4efc789192621, []int{5}
}
func (m *DeleteRequest) XXX_Unmarshal(b []byte) error {
@@ -320,7 +376,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} }
func (m *DeleteResponse) String() string { return proto.CompactTextString(m) }
func (*DeleteResponse) ProtoMessage() {}
func (*DeleteResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_2d32cca1c2f74735, []int{6}
return fileDescriptor_a1e4efc789192621, []int{6}
}
func (m *DeleteResponse) XXX_Unmarshal(b []byte) error {
@@ -351,30 +407,33 @@ func init() {
proto.RegisterType((*DeleteResponse)(nil), "posts.DeleteResponse")
}
func init() { proto.RegisterFile("blog/posts/proto/posts/post.proto", fileDescriptor_2d32cca1c2f74735) }
var fileDescriptor_2d32cca1c2f74735 = []byte{
// 343 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x4d, 0x4e, 0xc3, 0x30,
0x10, 0x85, 0x71, 0xf3, 0x03, 0x9d, 0xfe, 0x08, 0x4d, 0x0b, 0xb2, 0x22, 0xa4, 0xa6, 0x59, 0x65,
0x95, 0x8a, 0x82, 0xc4, 0x05, 0x58, 0xa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c,
0x24, 0x46, 0x25, 0xd5, 0x32, 0x44, 0xbd, 0x9c, 0x04, 0x06, 0x6f, 0xe9, 0xa7, 0x6c, 0x42, 0xcc,
0xc0, 0xad, 0xb8, 0x09, 0xd1, 0x29, 0x30, 0x17, 0xd1, 0x02, 0x86, 0xf6, 0x7d, 0xdd, 0xe2, 0xdf,
0x82, 0x19, 0x8c, 0x9e, 0x65, 0x2e, 0xa9, 0x6d, 0xd1, 0xf9, 0x0a, 0xd1, 0x35, 0x8c, 0x9b, 0x07,
0xd6, 0x73, 0xf9, 0xc3, 0xc0, 0xab, 0x1c, 0x34, 0x3e, 0x82, 0x67, 0x26, 0xc2, 0x49, 0x6d, 0x7c,
0xba, 0xb1, 0x60, 0x7a, 0x0e, 0x6d, 0x75, 0x74, 0x81, 0xf7, 0xe0, 0x56, 0x19, 0x11, 0xeb, 0xfb,
0x93, 0x01, 0x83, 0xc9, 0x19, 0x6b, 0x4b, 0x9e, 0xc0, 0xb7, 0x21, 0xb0, 0x31, 0x3d, 0x0b, 0x1d,
0xdc, 0x74, 0x68, 0x53, 0xb8, 0xf6, 0xcd, 0xaf, 0xf6, 0xf0, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xd5,
0xd2, 0x06, 0xac, 0x8f, 0x02, 0x00, 0x00,
func init() {
proto.RegisterFile("proto/posts/posts.proto", fileDescriptor_a1e4efc789192621)
}
var fileDescriptor_a1e4efc789192621 = []byte{
// 363 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x52, 0x5d, 0x4e, 0xf3, 0x30,
0x10, 0xfc, 0xd2, 0xfc, 0xf4, 0xeb, 0xf6, 0x47, 0x68, 0x5b, 0xc0, 0xaa, 0x10, 0x94, 0x3c, 0xf5,
0xa9, 0x88, 0x82, 0xc4, 0x05, 0x38, 0x40, 0x09, 0x27, 0x08, 0xd4, 0x2d, 0x91, 0xd2, 0x26, 0xc4,
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0xa6, 0x43, 0x5d, 0x59, 0x62, 0x2b,
0xfc, 0xf0, 0xa0, 0xfb, 0x98, 0xbe, 0x71, 0xe7, 0xe2, 0x2f, 0x9a, 0x3c, 0x83, 0x8e, 0xcc, 0x36,
0x4a, 0x3d, 0xdd, 0x94, 0xb6, 0xcb, 0x1f, 0x62, 0xd7, 0x4d, 0xd4, 0xe8, 0xe6, 0x1c, 0x7a, 0xc6,
0x94, 0x0d, 0x72, 0xe0, 0x2a, 0xbe, 0x80, 0xfe, 0x3d, 0xcf, 0xb9, 0xfc, 0xcd, 0x76, 0x7c, 0x04,
0x03, 0xf7, 0x82, 0x91, 0x98, 0x7f, 0x7a, 0x10, 0xea, 0xe0, 0x02, 0x6f, 0x21, 0xa4, 0x9a, 0x70,
0x68, 0xfb, 0x68, 0x7e, 0x86, 0xf1, 0x68, 0x9f, 0x34, 0xa7, 0xe3, 0x7f, 0x78, 0x0d, 0x81, 0xb6,
0x84, 0x68, 0xf7, 0x8d, 0xd2, 0xc6, 0xc3, 0x3d, 0x6e, 0x77, 0xe4, 0x0e, 0x22, 0x63, 0x02, 0x9d,
0xe8, 0x9e, 0xe9, 0xf1, 0xf1, 0x01, 0xeb, 0x0e, 0x3e, 0x45, 0xf4, 0x97, 0xdf, 0x7c, 0x07, 0x00,
0x00, 0xff, 0xff, 0xed, 0x03, 0x8f, 0x37, 0x00, 0x03, 0x00, 0x00,
}

View File

@@ -1,5 +1,5 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: blog/posts/proto/posts/post.proto
// source: proto/posts/posts.proto
package posts
@@ -11,9 +11,9 @@ import (
import (
context "context"
api "github.com/micro/go-micro/v3/api"
client "github.com/micro/go-micro/v3/client"
server "github.com/micro/go-micro/v3/server"
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.

View File

@@ -14,8 +14,10 @@ message Post {
string title = 2;
string slug = 3;
string content = 4;
int64 timestamp = 5;
repeated string tagNames = 6;
int64 created = 5;
int64 updated = 6;
string author = 7;
repeated string tags = 8;
}
message QueryRequest {
@@ -29,17 +31,21 @@ message QueryResponse {
}
message SaveRequest {
Post post = 1;
string id = 1;
string title = 2;
string slug = 3;
string content = 4;
int64 timestamp = 5;
repeated string tags = 6;
}
message SaveResponse {
Post post = 1;
string id = 1;
}
message DeleteRequest {
string id = 1;
}
message DeleteResponse {
}
message DeleteResponse {}

View File

@@ -5,7 +5,7 @@ MODIFY=Mgithub.com/micro/go-micro/api/proto/api.proto=github.com/micro/go-micro/
.PHONY: proto
proto:
protoc --proto_path=. --micro_out=${MODIFY}:. --go_out=${MODIFY}:. proto/tag/tag.proto
protoc --proto_path=. --micro_out=${MODIFY}:. --go_out=${MODIFY}:. proto/tags.proto
.PHONY: build

View File

@@ -8,100 +8,128 @@ import (
"github.com/gosimple/slug"
"github.com/micro/go-micro/v3/errors"
gostore "github.com/micro/go-micro/v3/store"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
pb "github.com/micro/services/blog/tags/proto"
)
const (
parentPrefix = "parent"
typePrefix = "type"
slugPrefix = "bySlug"
parentPrefix = "byParent"
typePrefix = "byType"
tagCountPrefix = "tagCount"
)
type Tag struct {
ParentID string `json:"parentID"`
Title string `json:"title"`
Slug string `json:"slug"`
Type string `json:"type"`
Count int64 `json:"count"`
Title string `json:"title"`
Slug string `json:"slug"`
Type string `json:"type"`
Count int64 `json:"count"`
}
type Tags struct{}
func (t *Tags) IncreaseCount(ctx context.Context, req *pb.IncreaseCountRequest, rsp *pb.IncreaseCountResponse) error {
func (t *Tags) Add(ctx context.Context, req *pb.AddRequest, rsp *pb.AddResponse) error {
if len(req.ParentID) == 0 || len(req.Type) == 0 {
return errors.BadRequest("tags.increasecount.input-check", "parent id and type is required")
}
tagSlug := slug.Make(req.GetTitle())
parentID := fmt.Sprintf("%v:%v:%v", parentPrefix, req.GetParentID(), tagSlug)
key := fmt.Sprintf("%v:%v", slugPrefix, tagSlug)
// read by parent ID + slug, the record is identical in boths places anyway
records, err := store.Read(parentID)
if err != nil && err != gostore.ErrNotFound {
records, err := store.Read(key)
if err != nil && err != store.ErrNotFound {
return err
}
var tag *Tag
// If no existing record is found, create a new one
if len(records) == 0 {
tag := &Tag{
ParentID: req.GetParentID(),
Title: req.GetTitle(),
Type: req.Type,
Slug: tagSlug,
Count: 1,
tag = &Tag{
Title: req.GetTitle(),
Type: req.Type,
Slug: tagSlug,
}
} else {
record := records[0]
tag = &Tag{}
err = json.Unmarshal(record.Value, tag)
if err != nil {
return err
}
return t.saveTag(tag)
}
record := records[0]
tag := &Tag{}
err = json.Unmarshal(record.Value, tag)
// increase tag count
err = store.Write(&store.Record{
Key: fmt.Sprintf("%v:%v:%v", tagCountPrefix, tag.Slug, req.GetParentID()),
Value: nil,
})
if err != nil {
return err
}
oldTagCount := tag.Count
// get tag count
recs, err := store.List(store.Prefix(fmt.Sprintf("%v:%v", tagCountPrefix, tag.Slug)), store.Limit(1000))
if err != nil {
return err
}
tag.Count = int64(len(recs))
if tag.Count == oldTagCount {
return fmt.Errorf("Tag count for tag %v is unchanged, was: %v, now: %v", tagSlug, oldTagCount, tag.Count)
}
tagJSON, err := json.Marshal(tag)
if err != nil {
return err
}
err = store.Write(&store.Record{
Key: fmt.Sprintf("%v:%v:%v", parentPrefix, req.GetParentID(), tag.Slug),
Value: tagJSON,
})
if err != nil {
return err
}
tag.Count++
return t.saveTag(tag)
}
func (t *Tags) saveTag(tag *Tag) error {
tagSlug := slug.Make(tag.Title)
parentID := fmt.Sprintf("%v:%v:%v", parentPrefix, tag.ParentID, tagSlug)
typeID := fmt.Sprintf("%v:%v:%v", typePrefix, tag.Type, tagSlug)
key := fmt.Sprintf("%v:%v", slugPrefix, tagSlug)
typeKey := fmt.Sprintf("%v:%v:%v", typePrefix, tag.Type, tagSlug)
bytes, err := json.Marshal(tag)
if err != nil {
return err
}
// write parentId:slug to enable prefix listing based on parent
err = store.Write(&gostore.Record{
Key: parentID,
// write parentId:slug to enable prefix listing based on type
err = store.Write(&store.Record{
Key: key,
Value: bytes,
})
if err != nil {
return err
}
// write type:slug to enable prefix listing based on parent
return store.Write(&gostore.Record{
Key: typeID,
return store.Write(&store.Record{
Key: typeKey,
Value: bytes,
})
}
func (t *Tags) DecreaseCount(ctx context.Context, req *pb.DecreaseCountRequest, rsp *pb.DecreaseCountResponse) error {
func (t *Tags) Remove(ctx context.Context, req *pb.RemoveRequest, rsp *pb.RemoveResponse) error {
if len(req.ParentID) == 0 || len(req.Type) == 0 {
return errors.BadRequest("tags.decreaseecount.input-check", "parent id and type is required")
}
tagSlug := slug.Make(req.GetTitle())
parentID := fmt.Sprintf("%v:%v:%v", parentPrefix, req.GetParentID(), tagSlug)
parentKey := fmt.Sprintf("%v:%v:%v", parentPrefix, req.GetParentID(), tagSlug)
// read by parent ID + slug, the record is identical in boths places anyway
records, err := store.Read(parentID)
if err != nil && err != gostore.ErrNotFound {
records, err := store.Read(parentKey)
if err != nil && err != store.ErrNotFound {
return err
}
@@ -116,11 +144,19 @@ func (t *Tags) DecreaseCount(ctx context.Context, req *pb.DecreaseCountRequest,
if err != nil {
return err
}
if tag.Count == 0 {
// return error?
return nil
// decrease tag count
err = store.Delete(fmt.Sprintf("%v:%v:%v", tagCountPrefix, tag.Slug, req.GetParentID()))
if err != nil {
return err
}
tag.Count--
// get tag count
recs, err := store.List(store.Prefix(fmt.Sprintf("%v:%v", tagCountPrefix, tag.Slug)), store.Limit(1000))
if err != nil {
return err
}
tag.Count = int64(len(recs))
return t.saveTag(tag)
}
@@ -139,6 +175,7 @@ func (t *Tags) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListRespon
if err != nil {
return err
}
rsp.Tags = make([]*pb.Tag, len(records))
for i, record := range records {
tagRecord := &Tag{}
@@ -147,23 +184,23 @@ func (t *Tags) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListRespon
return err
}
rsp.Tags[i] = &pb.Tag{
ParentID: tagRecord.ParentID,
Title: tagRecord.Title,
Type: tagRecord.Type,
Slug: tagRecord.Slug,
Count: tagRecord.Count,
Title: tagRecord.Title,
Type: tagRecord.Type,
Slug: tagRecord.Slug,
Count: tagRecord.Count,
}
}
return nil
}
func (t *Tags) Update(ctx context.Context, req *pb.UpdateRequest, rsp *pb.UpdateResponse) error {
if len(req.ParentID) == 0 || len(req.Type) == 0 {
return errors.BadRequest("tags.update.input-check", "parent id and type is required")
if len(req.Title) == 0 || len(req.Type) == 0 {
return errors.BadRequest("tags.update.input-check", "title and type is required")
}
tagSlug := slug.Make(req.GetTitle())
parentID := fmt.Sprintf("%v:%v:%v", parentPrefix, req.GetParentID(), tagSlug)
parentID := fmt.Sprintf("%v:%v", slugPrefix, tagSlug)
// read by parent ID + slug, the record is identical in boths places anyway
records, err := store.Read(parentID)

View File

@@ -1,5 +1,5 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: blog/tags/proto/tags.proto
// source: proto/tags.proto
package tags
@@ -21,13 +21,12 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Tag struct {
// The id of the parent object
ParentID string `protobuf:"bytes,1,opt,name=parentID,proto3" json:"parentID,omitempty"`
// Type is useful for namespacing and listing across parents,
// ie. list tags for posts, customers etc.
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Slug string `protobuf:"bytes,3,opt,name=slug,proto3" json:"slug,omitempty"`
Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"`
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
Slug string `protobuf:"bytes,2,opt,name=slug,proto3" json:"slug,omitempty"`
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
Count int64 `protobuf:"varint,5,opt,name=count,proto3" json:"count,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
@@ -38,7 +37,7 @@ func (m *Tag) Reset() { *m = Tag{} }
func (m *Tag) String() string { return proto.CompactTextString(m) }
func (*Tag) ProtoMessage() {}
func (*Tag) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{0}
return fileDescriptor_53c4e9b325a9c45b, []int{0}
}
func (m *Tag) XXX_Unmarshal(b []byte) error {
@@ -59,13 +58,6 @@ func (m *Tag) XXX_DiscardUnknown() {
var xxx_messageInfo_Tag proto.InternalMessageInfo
func (m *Tag) GetParentID() string {
if m != nil {
return m.ParentID
}
return ""
}
func (m *Tag) GetType() string {
if m != nil {
return m.Type
@@ -87,6 +79,13 @@ func (m *Tag) GetTitle() string {
return ""
}
func (m *Tag) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *Tag) GetCount() int64 {
if m != nil {
return m.Count
@@ -94,7 +93,7 @@ func (m *Tag) GetCount() int64 {
return 0
}
type IncreaseCountRequest struct {
type AddRequest struct {
ParentID string `protobuf:"bytes,1,opt,name=parentID,proto3" json:"parentID,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
@@ -103,84 +102,84 @@ type IncreaseCountRequest struct {
XXX_sizecache int32 `json:"-"`
}
func (m *IncreaseCountRequest) Reset() { *m = IncreaseCountRequest{} }
func (m *IncreaseCountRequest) String() string { return proto.CompactTextString(m) }
func (*IncreaseCountRequest) ProtoMessage() {}
func (*IncreaseCountRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{1}
func (m *AddRequest) Reset() { *m = AddRequest{} }
func (m *AddRequest) String() string { return proto.CompactTextString(m) }
func (*AddRequest) ProtoMessage() {}
func (*AddRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_53c4e9b325a9c45b, []int{1}
}
func (m *IncreaseCountRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_IncreaseCountRequest.Unmarshal(m, b)
func (m *AddRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_AddRequest.Unmarshal(m, b)
}
func (m *IncreaseCountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_IncreaseCountRequest.Marshal(b, m, deterministic)
func (m *AddRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_AddRequest.Marshal(b, m, deterministic)
}
func (m *IncreaseCountRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_IncreaseCountRequest.Merge(m, src)
func (m *AddRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_AddRequest.Merge(m, src)
}
func (m *IncreaseCountRequest) XXX_Size() int {
return xxx_messageInfo_IncreaseCountRequest.Size(m)
func (m *AddRequest) XXX_Size() int {
return xxx_messageInfo_AddRequest.Size(m)
}
func (m *IncreaseCountRequest) XXX_DiscardUnknown() {
xxx_messageInfo_IncreaseCountRequest.DiscardUnknown(m)
func (m *AddRequest) XXX_DiscardUnknown() {
xxx_messageInfo_AddRequest.DiscardUnknown(m)
}
var xxx_messageInfo_IncreaseCountRequest proto.InternalMessageInfo
var xxx_messageInfo_AddRequest proto.InternalMessageInfo
func (m *IncreaseCountRequest) GetParentID() string {
func (m *AddRequest) GetParentID() string {
if m != nil {
return m.ParentID
}
return ""
}
func (m *IncreaseCountRequest) GetType() string {
func (m *AddRequest) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *IncreaseCountRequest) GetTitle() string {
func (m *AddRequest) GetTitle() string {
if m != nil {
return m.Title
}
return ""
}
type IncreaseCountResponse struct {
type AddResponse struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *IncreaseCountResponse) Reset() { *m = IncreaseCountResponse{} }
func (m *IncreaseCountResponse) String() string { return proto.CompactTextString(m) }
func (*IncreaseCountResponse) ProtoMessage() {}
func (*IncreaseCountResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{2}
func (m *AddResponse) Reset() { *m = AddResponse{} }
func (m *AddResponse) String() string { return proto.CompactTextString(m) }
func (*AddResponse) ProtoMessage() {}
func (*AddResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_53c4e9b325a9c45b, []int{2}
}
func (m *IncreaseCountResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_IncreaseCountResponse.Unmarshal(m, b)
func (m *AddResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_AddResponse.Unmarshal(m, b)
}
func (m *IncreaseCountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_IncreaseCountResponse.Marshal(b, m, deterministic)
func (m *AddResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_AddResponse.Marshal(b, m, deterministic)
}
func (m *IncreaseCountResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_IncreaseCountResponse.Merge(m, src)
func (m *AddResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_AddResponse.Merge(m, src)
}
func (m *IncreaseCountResponse) XXX_Size() int {
return xxx_messageInfo_IncreaseCountResponse.Size(m)
func (m *AddResponse) XXX_Size() int {
return xxx_messageInfo_AddResponse.Size(m)
}
func (m *IncreaseCountResponse) XXX_DiscardUnknown() {
xxx_messageInfo_IncreaseCountResponse.DiscardUnknown(m)
func (m *AddResponse) XXX_DiscardUnknown() {
xxx_messageInfo_AddResponse.DiscardUnknown(m)
}
var xxx_messageInfo_IncreaseCountResponse proto.InternalMessageInfo
var xxx_messageInfo_AddResponse proto.InternalMessageInfo
type DecreaseCountRequest struct {
type RemoveRequest struct {
ParentID string `protobuf:"bytes,1,opt,name=parentID,proto3" json:"parentID,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
@@ -189,87 +188,87 @@ type DecreaseCountRequest struct {
XXX_sizecache int32 `json:"-"`
}
func (m *DecreaseCountRequest) Reset() { *m = DecreaseCountRequest{} }
func (m *DecreaseCountRequest) String() string { return proto.CompactTextString(m) }
func (*DecreaseCountRequest) ProtoMessage() {}
func (*DecreaseCountRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{3}
func (m *RemoveRequest) Reset() { *m = RemoveRequest{} }
func (m *RemoveRequest) String() string { return proto.CompactTextString(m) }
func (*RemoveRequest) ProtoMessage() {}
func (*RemoveRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_53c4e9b325a9c45b, []int{3}
}
func (m *DecreaseCountRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_DecreaseCountRequest.Unmarshal(m, b)
func (m *RemoveRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RemoveRequest.Unmarshal(m, b)
}
func (m *DecreaseCountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_DecreaseCountRequest.Marshal(b, m, deterministic)
func (m *RemoveRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RemoveRequest.Marshal(b, m, deterministic)
}
func (m *DecreaseCountRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_DecreaseCountRequest.Merge(m, src)
func (m *RemoveRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_RemoveRequest.Merge(m, src)
}
func (m *DecreaseCountRequest) XXX_Size() int {
return xxx_messageInfo_DecreaseCountRequest.Size(m)
func (m *RemoveRequest) XXX_Size() int {
return xxx_messageInfo_RemoveRequest.Size(m)
}
func (m *DecreaseCountRequest) XXX_DiscardUnknown() {
xxx_messageInfo_DecreaseCountRequest.DiscardUnknown(m)
func (m *RemoveRequest) XXX_DiscardUnknown() {
xxx_messageInfo_RemoveRequest.DiscardUnknown(m)
}
var xxx_messageInfo_DecreaseCountRequest proto.InternalMessageInfo
var xxx_messageInfo_RemoveRequest proto.InternalMessageInfo
func (m *DecreaseCountRequest) GetParentID() string {
func (m *RemoveRequest) GetParentID() string {
if m != nil {
return m.ParentID
}
return ""
}
func (m *DecreaseCountRequest) GetType() string {
func (m *RemoveRequest) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *DecreaseCountRequest) GetTitle() string {
func (m *RemoveRequest) GetTitle() string {
if m != nil {
return m.Title
}
return ""
}
type DecreaseCountResponse struct {
type RemoveResponse struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *DecreaseCountResponse) Reset() { *m = DecreaseCountResponse{} }
func (m *DecreaseCountResponse) String() string { return proto.CompactTextString(m) }
func (*DecreaseCountResponse) ProtoMessage() {}
func (*DecreaseCountResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{4}
func (m *RemoveResponse) Reset() { *m = RemoveResponse{} }
func (m *RemoveResponse) String() string { return proto.CompactTextString(m) }
func (*RemoveResponse) ProtoMessage() {}
func (*RemoveResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_53c4e9b325a9c45b, []int{4}
}
func (m *DecreaseCountResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_DecreaseCountResponse.Unmarshal(m, b)
func (m *RemoveResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RemoveResponse.Unmarshal(m, b)
}
func (m *DecreaseCountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_DecreaseCountResponse.Marshal(b, m, deterministic)
func (m *RemoveResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RemoveResponse.Marshal(b, m, deterministic)
}
func (m *DecreaseCountResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_DecreaseCountResponse.Merge(m, src)
func (m *RemoveResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_RemoveResponse.Merge(m, src)
}
func (m *DecreaseCountResponse) XXX_Size() int {
return xxx_messageInfo_DecreaseCountResponse.Size(m)
func (m *RemoveResponse) XXX_Size() int {
return xxx_messageInfo_RemoveResponse.Size(m)
}
func (m *DecreaseCountResponse) XXX_DiscardUnknown() {
xxx_messageInfo_DecreaseCountResponse.DiscardUnknown(m)
func (m *RemoveResponse) XXX_DiscardUnknown() {
xxx_messageInfo_RemoveResponse.DiscardUnknown(m)
}
var xxx_messageInfo_DecreaseCountResponse proto.InternalMessageInfo
var xxx_messageInfo_RemoveResponse proto.InternalMessageInfo
type UpdateRequest struct {
ParentID string `protobuf:"bytes,1,opt,name=parentID,proto3" json:"parentID,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -279,7 +278,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} }
func (m *UpdateRequest) String() string { return proto.CompactTextString(m) }
func (*UpdateRequest) ProtoMessage() {}
func (*UpdateRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{5}
return fileDescriptor_53c4e9b325a9c45b, []int{5}
}
func (m *UpdateRequest) XXX_Unmarshal(b []byte) error {
@@ -300,13 +299,6 @@ func (m *UpdateRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_UpdateRequest proto.InternalMessageInfo
func (m *UpdateRequest) GetParentID() string {
if m != nil {
return m.ParentID
}
return ""
}
func (m *UpdateRequest) GetType() string {
if m != nil {
return m.Type
@@ -321,6 +313,13 @@ func (m *UpdateRequest) GetTitle() string {
return ""
}
func (m *UpdateRequest) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
type UpdateResponse struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
@@ -331,7 +330,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} }
func (m *UpdateResponse) String() string { return proto.CompactTextString(m) }
func (*UpdateResponse) ProtoMessage() {}
func (*UpdateResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_3298e21a718ae8a1, []int{6}
return fileDescriptor_53c4e9b325a9c45b, []int{6}
}
func (m *UpdateResponse) XXX_Unmarshal(b []byte) error {
@@ -368,7 +367,7 @@ 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_3298e21a718ae8a1, []int{7}
return fileDescriptor_53c4e9b325a9c45b, []int{7}
}
func (m *ListRequest) XXX_Unmarshal(b []byte) error {
@@ -428,7 +427,7 @@ 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_3298e21a718ae8a1, []int{8}
return fileDescriptor_53c4e9b325a9c45b, []int{8}
}
func (m *ListResponse) XXX_Unmarshal(b []byte) error {
@@ -458,40 +457,43 @@ func (m *ListResponse) GetTags() []*Tag {
func init() {
proto.RegisterType((*Tag)(nil), "tags.Tag")
proto.RegisterType((*IncreaseCountRequest)(nil), "tags.IncreaseCountRequest")
proto.RegisterType((*IncreaseCountResponse)(nil), "tags.IncreaseCountResponse")
proto.RegisterType((*DecreaseCountRequest)(nil), "tags.DecreaseCountRequest")
proto.RegisterType((*DecreaseCountResponse)(nil), "tags.DecreaseCountResponse")
proto.RegisterType((*AddRequest)(nil), "tags.AddRequest")
proto.RegisterType((*AddResponse)(nil), "tags.AddResponse")
proto.RegisterType((*RemoveRequest)(nil), "tags.RemoveRequest")
proto.RegisterType((*RemoveResponse)(nil), "tags.RemoveResponse")
proto.RegisterType((*UpdateRequest)(nil), "tags.UpdateRequest")
proto.RegisterType((*UpdateResponse)(nil), "tags.UpdateResponse")
proto.RegisterType((*ListRequest)(nil), "tags.ListRequest")
proto.RegisterType((*ListResponse)(nil), "tags.ListResponse")
}
func init() { proto.RegisterFile("blog/tags/proto/tags.proto", fileDescriptor_3298e21a718ae8a1) }
var fileDescriptor_3298e21a718ae8a1 = []byte{
// 341 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0x41, 0x4f, 0x32, 0x31,
0x10, 0x65, 0xd9, 0x42, 0x60, 0xf8, 0xf8, 0xa2, 0x23, 0xc6, 0xa6, 0xc6, 0x84, 0xec, 0x89, 0x8b,
0x90, 0x60, 0xfc, 0x05, 0x72, 0xc1, 0x78, 0xda, 0xc0, 0xcd, 0x4b, 0xc1, 0xa6, 0x21, 0xc1, 0xdd,
0x95, 0x76, 0x13, 0xfd, 0x03, 0xfe, 0x6e, 0xd3, 0xe9, 0xee, 0x86, 0x25, 0x7b, 0xd1, 0xe8, 0x6d,
0xe6, 0x4d, 0xfb, 0xde, 0x4c, 0xdf, 0x14, 0xc4, 0x66, 0x9f, 0xea, 0x99, 0x95, 0xda, 0xcc, 0xb2,
0x43, 0x6a, 0x53, 0x0a, 0xa7, 0x14, 0x22, 0x73, 0x71, 0x94, 0x43, 0xb8, 0x92, 0x1a, 0x05, 0xf4,
0x32, 0x79, 0x50, 0x89, 0x5d, 0x2e, 0x78, 0x30, 0x0e, 0x26, 0xfd, 0xb8, 0xca, 0x11, 0x81, 0xd9,
0x8f, 0x4c, 0xf1, 0x36, 0xe1, 0x14, 0x3b, 0xcc, 0xec, 0x73, 0xcd, 0x43, 0x8f, 0xb9, 0x18, 0x47,
0xd0, 0xb1, 0x3b, 0xbb, 0x57, 0x9c, 0x11, 0x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
0xc1, 0xf2, 0xda, 0xa6, 0x4b, 0x3f, 0xf1, 0xee, 0x2b, 0x00, 0x00, 0xff, 0xff, 0xa9, 0xd1, 0x76,
0x1f, 0xa7, 0x03, 0x00, 0x00,
func init() {
proto.RegisterFile("proto/tags.proto", fileDescriptor_53c4e9b325a9c45b)
}
var fileDescriptor_53c4e9b325a9c45b = []byte{
// 357 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x53, 0x41, 0x4b, 0xf3, 0x40,
0x10, 0x6d, 0xbb, 0x69, 0xf9, 0x3a, 0xf9, 0x2a, 0x75, 0xec, 0x21, 0x04, 0x84, 0x92, 0x53, 0x0f,
0xda, 0x42, 0xc5, 0x1f, 0x20, 0x7a, 0x11, 0x3c, 0x05, 0x7b, 0xf2, 0x14, 0x9b, 0xa5, 0x04, 0xda,
0x24, 0x76, 0x37, 0xa2, 0xf8, 0x33, 0xfd, 0x43, 0x66, 0x67, 0x37, 0xeb, 0x46, 0x8b, 0x07, 0xf1,
0x36, 0xf3, 0x26, 0x3b, 0xef, 0xed, 0x7b, 0x1b, 0x18, 0x97, 0xfb, 0x42, 0x16, 0x0b, 0x99, 0x6c,
0xc4, 0x9c, 0x4a, 0xf4, 0x54, 0x1d, 0xbd, 0x01, 0xbb, 0x4f, 0x36, 0x88, 0xe0, 0xc9, 0xd7, 0x92,
0x07, 0xdd, 0x69, 0x77, 0x36, 0x8c, 0xa9, 0x56, 0x98, 0xd8, 0x56, 0x9b, 0xa0, 0xa7, 0x31, 0x55,
0xe3, 0x04, 0xfa, 0x32, 0x93, 0x5b, 0x1e, 0x30, 0x02, 0x75, 0x83, 0x53, 0xf0, 0x53, 0x2e, 0xd6,
0xfb, 0xac, 0x94, 0x59, 0x91, 0x07, 0x1e, 0xcd, 0x5c, 0x48, 0x9d, 0x5b, 0x17, 0x55, 0x2e, 0x83,
0x7e, 0x3d, 0x63, 0xb1, 0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x95, 0x60, 0xc3, 0xf3, 0xc5,
0xf9, 0xce, 0xe3, 0x80, 0x7e, 0xa0, 0x8b, 0x8f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdd, 0x86, 0xfc,
0x24, 0x54, 0x03, 0x00, 0x00,
}

View File

@@ -1,5 +1,5 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: blog/tags/proto/tags.proto
// source: proto/tags.proto
package tags
@@ -11,9 +11,9 @@ import (
import (
context "context"
api "github.com/micro/go-micro/v3/api"
client "github.com/micro/go-micro/v3/client"
server "github.com/micro/go-micro/v3/server"
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.
@@ -42,12 +42,13 @@ func NewTagsEndpoints() []*api.Endpoint {
// Client API for Tags service
type TagsService interface {
// Increase count creates the tag or bumps the counter
IncreaseCount(ctx context.Context, in *IncreaseCountRequest, opts ...client.CallOption) (*IncreaseCountResponse, error)
// Decreases the counter
DecreaseCount(ctx context.Context, in *DecreaseCountRequest, opts ...client.CallOption) (*DecreaseCountResponse, error)
// Add a tag to a parent
Add(ctx context.Context, in *AddRequest, opts ...client.CallOption) (*AddResponse, error)
// Remove a tag from a parent
Remove(ctx context.Context, in *RemoveRequest, opts ...client.CallOption) (*RemoveResponse, error)
// List tags by
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
// Change properties of a tag, currently only the title
// Change properties of a tag, currently only the title and description
Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error)
}
@@ -63,9 +64,9 @@ func NewTagsService(name string, c client.Client) TagsService {
}
}
func (c *tagsService) IncreaseCount(ctx context.Context, in *IncreaseCountRequest, opts ...client.CallOption) (*IncreaseCountResponse, error) {
req := c.c.NewRequest(c.name, "Tags.IncreaseCount", in)
out := new(IncreaseCountResponse)
func (c *tagsService) Add(ctx context.Context, in *AddRequest, opts ...client.CallOption) (*AddResponse, error) {
req := c.c.NewRequest(c.name, "Tags.Add", in)
out := new(AddResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
@@ -73,9 +74,9 @@ func (c *tagsService) IncreaseCount(ctx context.Context, in *IncreaseCountReques
return out, nil
}
func (c *tagsService) DecreaseCount(ctx context.Context, in *DecreaseCountRequest, opts ...client.CallOption) (*DecreaseCountResponse, error) {
req := c.c.NewRequest(c.name, "Tags.DecreaseCount", in)
out := new(DecreaseCountResponse)
func (c *tagsService) Remove(ctx context.Context, in *RemoveRequest, opts ...client.CallOption) (*RemoveResponse, error) {
req := c.c.NewRequest(c.name, "Tags.Remove", in)
out := new(RemoveResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
@@ -106,19 +107,20 @@ func (c *tagsService) Update(ctx context.Context, in *UpdateRequest, opts ...cli
// Server API for Tags service
type TagsHandler interface {
// Increase count creates the tag or bumps the counter
IncreaseCount(context.Context, *IncreaseCountRequest, *IncreaseCountResponse) error
// Decreases the counter
DecreaseCount(context.Context, *DecreaseCountRequest, *DecreaseCountResponse) error
// Add a tag to a parent
Add(context.Context, *AddRequest, *AddResponse) error
// Remove a tag from a parent
Remove(context.Context, *RemoveRequest, *RemoveResponse) error
// List tags by
List(context.Context, *ListRequest, *ListResponse) error
// Change properties of a tag, currently only the title
// Change properties of a tag, currently only the title and description
Update(context.Context, *UpdateRequest, *UpdateResponse) error
}
func RegisterTagsHandler(s server.Server, hdlr TagsHandler, opts ...server.HandlerOption) error {
type tags interface {
IncreaseCount(ctx context.Context, in *IncreaseCountRequest, out *IncreaseCountResponse) error
DecreaseCount(ctx context.Context, in *DecreaseCountRequest, out *DecreaseCountResponse) error
Add(ctx context.Context, in *AddRequest, out *AddResponse) error
Remove(ctx context.Context, in *RemoveRequest, out *RemoveResponse) error
List(ctx context.Context, in *ListRequest, out *ListResponse) error
Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error
}
@@ -133,12 +135,12 @@ type tagsHandler struct {
TagsHandler
}
func (h *tagsHandler) IncreaseCount(ctx context.Context, in *IncreaseCountRequest, out *IncreaseCountResponse) error {
return h.TagsHandler.IncreaseCount(ctx, in, out)
func (h *tagsHandler) Add(ctx context.Context, in *AddRequest, out *AddResponse) error {
return h.TagsHandler.Add(ctx, in, out)
}
func (h *tagsHandler) DecreaseCount(ctx context.Context, in *DecreaseCountRequest, out *DecreaseCountResponse) error {
return h.TagsHandler.DecreaseCount(ctx, in, out)
func (h *tagsHandler) Remove(ctx context.Context, in *RemoveRequest, out *RemoveResponse) error {
return h.TagsHandler.Remove(ctx, in, out)
}
func (h *tagsHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error {

View File

@@ -3,46 +3,46 @@ syntax = "proto3";
package tags;
service Tags {
// Increase count creates the tag or bumps the counter
rpc IncreaseCount(IncreaseCountRequest) returns (IncreaseCountResponse) {}
// Decreases the counter
rpc DecreaseCount(DecreaseCountRequest) returns (DecreaseCountResponse) {}
// Add a tag to a parent
rpc Add(AddRequest) returns (AddResponse) {}
// Remove a tag from a parent
rpc Remove(RemoveRequest) returns (RemoveResponse) {}
// List tags by
rpc List(ListRequest) returns (ListResponse) {}
// Change properties of a tag, currently only the title
// Change properties of a tag, currently only the title and description
rpc Update(UpdateRequest) returns (UpdateResponse){}
}
message Tag {
// The id of the parent object
string parentID = 1;
// Type is useful for namespacing and listing across parents,
// ie. list tags for posts, customers etc.
string type = 2;
string slug = 3;
string title = 4;
string type = 1;
string slug = 2;
string title = 3;
string description = 4;
int64 count = 5;
}
message IncreaseCountRequest {
message AddRequest {
string parentID = 1;
string type = 2;
string title = 3;
}
message IncreaseCountResponse{}
message AddResponse{}
message DecreaseCountRequest{
message RemoveRequest {
string parentID = 1;
string type = 2;
string title = 3;
}
message DecreaseCountResponse{}
message RemoveResponse{}
message UpdateRequest {
string parentID = 1;
string type = 2;
string title = 3;
string type = 1;
string title = 2;
string description = 3;
}
message UpdateResponse{}