diff --git a/.gitignore b/.gitignore index 264bd81..c4b9ed5 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ fabric.properties /storage .env docker-compose.yml +/bin +/pkg diff --git a/README.md b/README.md index 9d3c31f..dbdb9b9 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,12 @@ To prerender some URL you need to specify it as a query parameter, like this: http://localhost:3000/render?url=https://www.example.com/ ``` -#### Purge cache +#### Clear cache Cached pages are valid for 7 days by default, but you can force clear it. -To purge all cached pages you need to pass the `Cache-Control` header -with the value `must-revalidate` or the `Clear-Site-Data` header with any value. +To purge all cached pages you need to send the`Clear-Site-Data` header with the value `*`. To remove only one page from +cache, just pass `Cache-Control` header with the value `must-revalidate`. Just send a usual request to @@ -48,13 +48,13 @@ Just send a usual request to http://localhost:3000/render?url=https://www.example.com/ ``` -With this header +With this header, to remove the cached page ``` Cache-Control: must-revalidate ``` -or +or, to flush all cache ``` Clear-Site-Data: * diff --git a/docker-compose.example.yml b/docker-compose.example.yml index c5b717b..cb7f302 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -5,9 +5,8 @@ services: build: context: ./ dockerfile: ./docker/server/Dockerfile - environment: - STORAGE_URL: 'storage:50051' - PAGE_WAIT_TIME: 5 + env_file: + - src/.env ports: - '${SERVER_PORT}:3000' links: @@ -17,5 +16,7 @@ services: build: context: ./ dockerfile: ./docker/storage/Dockerfile + env_file: + - src/.env ports: - '${STORAGE_PORT}:50051' diff --git a/src/.env.example b/src/.env.example index 377af44..2e90b2e 100644 --- a/src/.env.example +++ b/src/.env.example @@ -1,2 +1,3 @@ STORAGE_URL='storage:50051' PAGE_WAIT_TIME=5 +CACHE_EXPIRATION_TIME=168 diff --git a/src/api/proto/storage.proto b/src/api/proto/storage.proto index f0095d5..8becf2d 100644 --- a/src/api/proto/storage.proto +++ b/src/api/proto/storage.proto @@ -14,6 +14,8 @@ service Storage { // Get a request from storage rpc Get(GetRequest) returns (GetReplay) {} // + rpc Remove(RemoveRequest) returns (RemoveReply) {} + // rpc Len(LenRequest) returns (LenReplay) {} // rpc Purge(PurgeRequest) returns (PurgeReply) {} @@ -48,12 +50,20 @@ message GetRequest { string hash = 1; } +message RemoveRequest { + string hash = 1; +} + // Tre replay message message GetReplay { bytes data = 1; bool result = 2; } +message RemoveReply { + bool result = 2; +} + message LenRequest {} message LenReplay { diff --git a/src/cmd/server/main.go b/src/cmd/server/main.go index 295a1ca..b3a7743 100644 --- a/src/cmd/server/main.go +++ b/src/cmd/server/main.go @@ -20,6 +20,7 @@ import ( "prerender/internal/healthcheck" "prerender/internal/renderer" "prerender/internal/sitemap" + "prerender/internal/urlparser" "prerender/pkg/api/storage" prLog "prerender/pkg/log" "time" @@ -149,7 +150,6 @@ func startCroneRefresh(ctx context.Context, c *cron.Cron, pc cachers.Сacher, lo func handleRequest(ctx context.Context, pc cachers.Сacher, logger prLog.Logger) routing.Handler { return func(c *routing.Context) error { - queryString := c.Request.URL.Query().Get("url") newTabCtx, cancel := chromedp.NewContext(ctx) @@ -158,8 +158,18 @@ func handleRequest(ctx context.Context, pc cachers.Сacher, logger prLog.Logger) req := c.Request - if req.Header.Get("Cache-Control") == "must-revalidate" || req.Header.Get("Clear-Site-Data") != "" { + if req.Header.Get("Clear-Site-Data") == "*" { pc.Purge() + } else if req.Header.Get("Cache-Control") == "must-revalidate" { + key, err := urlparser.GetHashKey(queryString) + if err != nil { + return err + } + + _, err = pc.Remove(key) + if err != nil { + return err + } } res, err := renderer.DoRender(ctx, queryString, pc, false, logger) diff --git a/src/cmd/storage/main.go b/src/cmd/storage/main.go index 4f40161..f54ebfe 100644 --- a/src/cmd/storage/main.go +++ b/src/cmd/storage/main.go @@ -11,15 +11,17 @@ import ( "os" "os/signal" "prerender/pkg/api/storage" + "strconv" "syscall" "time" ) const ( - port = ":50051" - duration = time.Hour * 24 * 7 + port = ":50051" ) +var duration = time.Hour * 24 * 7 + var gc = gcache.New(100000). LRU(). Build() @@ -42,6 +44,7 @@ func (s *server) Store(ctx context.Context, in *storage.StoreRequest) (*storage. func (s *server) Get(ctx context.Context, in *storage.GetRequest) (*storage.GetReplay, error) { //log.Printf("Received: %v", in.GetHash()) value, err := gc.Get(in.Hash) + if err != nil { return nil, status.Error(codes.NotFound, "not found") } @@ -50,6 +53,14 @@ func (s *server) Get(ctx context.Context, in *storage.GetRequest) (*storage.GetR }, nil } +func (s *server) Remove(ctx context.Context, in *storage.RemoveRequest) (*storage.RemoveReply, error) { + //log.Printf("Received: %v", in.GetHash()) + result := gc.Remove(in.Hash) + return &storage.RemoveReply{ + Result: result, + }, nil +} + func (s *server) Len(ctx context.Context, in *storage.LenRequest) (*storage.LenReplay, error) { //log.Printf("Received: Len request") return &storage.LenReplay{Length: int32(gc.Len(true))}, nil @@ -62,6 +73,16 @@ func (s *server) Purge(ctx context.Context, in *storage.PurgeRequest) (*storage. } func main() { + durationStr, exists := os.LookupEnv("CACHE_EXPIRATION_TIME") + if exists && durationStr != "" { + durationHours, err := strconv.Atoi(durationStr) + if err != nil { + log.Fatalf("failed to parse env: %v", err) + } + + duration = time.Hour * time.Duration(durationHours) + } + ctx := context.Background() lis, err := net.Listen("tcp", port) if err != nil { diff --git a/src/internal/cachers/cacher.go b/src/internal/cachers/cacher.go index 290a2b9..3af9595 100644 --- a/src/internal/cachers/cacher.go +++ b/src/internal/cachers/cacher.go @@ -3,6 +3,7 @@ package cachers type Сacher interface { Put(key string, data []byte) error Get(key string) ([]byte, error) + Remove(key string) (bool, error) Len() int Purge() } diff --git a/src/internal/cachers/inmemory/repository.go b/src/internal/cachers/inmemory/repository.go index 18d5992..afd4165 100644 --- a/src/internal/cachers/inmemory/repository.go +++ b/src/internal/cachers/inmemory/repository.go @@ -27,6 +27,10 @@ func (r repository) Get(key string) ([]byte, error) { return value.([]byte), nil } +func (r repository) Remove(key string) (bool, error) { + return r.gc.Remove(key), nil +} + func (r repository) Len() int { return r.gc.Len(true) } diff --git a/src/internal/cachers/rstorage/service.go b/src/internal/cachers/rstorage/service.go index 87e5cec..81727df 100644 --- a/src/internal/cachers/rstorage/service.go +++ b/src/internal/cachers/rstorage/service.go @@ -42,6 +42,13 @@ func (s server) Get(key string) ([]byte, error) { return result.GetData(), err } +func (s server) Remove(key string) (bool, error) { + ctx := context.Background() + req := storage.RemoveRequest{Hash: key} + result, err := s.gw.Remove(ctx, &req) + return result.GetResult(), err +} + func (s server) Len() int { ctx := context.Background() req := storage.LenRequest{} diff --git a/src/internal/renderer/renderer.go b/src/internal/renderer/renderer.go index 7fa3d93..51467c7 100644 --- a/src/internal/renderer/renderer.go +++ b/src/internal/renderer/renderer.go @@ -2,28 +2,25 @@ package renderer import ( "context" - "crypto/sha256" "encoding/json" "fmt" "github.com/chromedp/cdproto/dom" "github.com/chromedp/chromedp" "net/http" - "net/url" "os" "prerender/internal/archive" "prerender/internal/cachers" + "prerender/internal/urlparser" "prerender/pkg/log" "strconv" - "strings" "time" ) func DoRender(ctx context.Context, queryString string, pc cachers.Сacher, force bool, logger log.Logger) (string, error) { waitSecondsStr, exists := os.LookupEnv("PAGE_WAIT_TIME") - waitSeconds := 5 - if exists { + if exists && waitSecondsStr != "" { var err error waitSeconds, err = strconv.Atoi(waitSecondsStr) @@ -32,26 +29,19 @@ func DoRender(ctx context.Context, queryString string, pc cachers.Сacher, force } } - u, err := url.Parse(queryString) + requestURL, hostPath, err := urlparser.ParseUrl(queryString) if err != nil { logger.Error(err) } - requestURL := "" - hostPath := "" - - if u.Path != "/" && strings.HasSuffix(u.Path, "/") { - path := strings.TrimRight(u.Path, "/") - requestURL = u.Scheme + "://" + u.Host + path - hostPath = u.Host + path - } else { - requestURL = queryString - hostPath = u.Host + u.Path + key, err := urlparser.GetHashKey(queryString) + if err != nil { + logger.Error(err) } - var res string - key := fmt.Sprintf("%x", sha256.Sum256([]byte(hostPath))) value, err := pc.Get(key) + var res string + if force || err != nil { err := chromedp.Run(ctx, chromedp.Navigate(requestURL), diff --git a/src/internal/urlparser/urlparser.go b/src/internal/urlparser/urlparser.go new file mode 100644 index 0000000..1b1a800 --- /dev/null +++ b/src/internal/urlparser/urlparser.go @@ -0,0 +1,35 @@ +package urlparser + +import ( + "crypto/sha256" + "fmt" + "net/url" + "strings" +) + +func ParseUrl(queryString string) (string, string, error) { + u, err := url.Parse(queryString) + if err != nil { + return "", "", err + } + + requestURL := "" + hostPath := "" + + if u.Path != "/" && strings.HasSuffix(u.Path, "/") { + path := strings.TrimRight(u.Path, "/") + requestURL = u.Scheme + "://" + u.Host + path + hostPath = u.Host + path + } else { + requestURL = queryString + hostPath = u.Host + u.Path + } + + return requestURL, hostPath, err +} + +func GetHashKey(queryString string) (string, error) { + _, hostPath, err := ParseUrl(queryString) + + return fmt.Sprintf("%x", sha256.Sum256([]byte(hostPath))), err +} diff --git a/src/pkg/api/storage/storage.pb.go b/src/pkg/api/storage/storage.pb.go index 7af2c67..aa0eb2a 100644 --- a/src/pkg/api/storage/storage.pb.go +++ b/src/pkg/api/storage/storage.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.0 -// protoc v3.19.4 +// protoc v3.20.1 // source: storage.proto package storage @@ -239,6 +239,53 @@ func (x *GetRequest) GetHash() string { return "" } +type RemoveRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (x *RemoveRequest) Reset() { + *x = RemoveRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_storage_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RemoveRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RemoveRequest) ProtoMessage() {} + +func (x *RemoveRequest) ProtoReflect() protoreflect.Message { + mi := &file_storage_proto_msgTypes[4] + 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 RemoveRequest.ProtoReflect.Descriptor instead. +func (*RemoveRequest) Descriptor() ([]byte, []int) { + return file_storage_proto_rawDescGZIP(), []int{4} +} + +func (x *RemoveRequest) GetHash() string { + if x != nil { + return x.Hash + } + return "" +} + // Tre replay message type GetReplay struct { state protoimpl.MessageState @@ -252,7 +299,7 @@ type GetReplay struct { func (x *GetReplay) Reset() { *x = GetReplay{} if protoimpl.UnsafeEnabled { - mi := &file_storage_proto_msgTypes[4] + mi := &file_storage_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -265,7 +312,7 @@ func (x *GetReplay) String() string { func (*GetReplay) ProtoMessage() {} func (x *GetReplay) ProtoReflect() protoreflect.Message { - mi := &file_storage_proto_msgTypes[4] + mi := &file_storage_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -278,7 +325,7 @@ func (x *GetReplay) ProtoReflect() protoreflect.Message { // Deprecated: Use GetReplay.ProtoReflect.Descriptor instead. func (*GetReplay) Descriptor() ([]byte, []int) { - return file_storage_proto_rawDescGZIP(), []int{4} + return file_storage_proto_rawDescGZIP(), []int{5} } func (x *GetReplay) GetData() []byte { @@ -295,6 +342,53 @@ func (x *GetReplay) GetResult() bool { return false } +type RemoveReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result bool `protobuf:"varint,2,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *RemoveReply) Reset() { + *x = RemoveReply{} + if protoimpl.UnsafeEnabled { + mi := &file_storage_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RemoveReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RemoveReply) ProtoMessage() {} + +func (x *RemoveReply) ProtoReflect() protoreflect.Message { + mi := &file_storage_proto_msgTypes[6] + 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 RemoveReply.ProtoReflect.Descriptor instead. +func (*RemoveReply) Descriptor() ([]byte, []int) { + return file_storage_proto_rawDescGZIP(), []int{6} +} + +func (x *RemoveReply) GetResult() bool { + if x != nil { + return x.Result + } + return false +} + type LenRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -304,7 +398,7 @@ type LenRequest struct { func (x *LenRequest) Reset() { *x = LenRequest{} if protoimpl.UnsafeEnabled { - mi := &file_storage_proto_msgTypes[5] + mi := &file_storage_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -317,7 +411,7 @@ func (x *LenRequest) String() string { func (*LenRequest) ProtoMessage() {} func (x *LenRequest) ProtoReflect() protoreflect.Message { - mi := &file_storage_proto_msgTypes[5] + mi := &file_storage_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -330,7 +424,7 @@ func (x *LenRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use LenRequest.ProtoReflect.Descriptor instead. func (*LenRequest) Descriptor() ([]byte, []int) { - return file_storage_proto_rawDescGZIP(), []int{5} + return file_storage_proto_rawDescGZIP(), []int{7} } type LenReplay struct { @@ -344,7 +438,7 @@ type LenReplay struct { func (x *LenReplay) Reset() { *x = LenReplay{} if protoimpl.UnsafeEnabled { - mi := &file_storage_proto_msgTypes[6] + mi := &file_storage_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -357,7 +451,7 @@ func (x *LenReplay) String() string { func (*LenReplay) ProtoMessage() {} func (x *LenReplay) ProtoReflect() protoreflect.Message { - mi := &file_storage_proto_msgTypes[6] + mi := &file_storage_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -370,7 +464,7 @@ func (x *LenReplay) ProtoReflect() protoreflect.Message { // Deprecated: Use LenReplay.ProtoReflect.Descriptor instead. func (*LenReplay) Descriptor() ([]byte, []int) { - return file_storage_proto_rawDescGZIP(), []int{6} + return file_storage_proto_rawDescGZIP(), []int{8} } func (x *LenReplay) GetLength() int32 { @@ -389,7 +483,7 @@ type PurgeRequest struct { func (x *PurgeRequest) Reset() { *x = PurgeRequest{} if protoimpl.UnsafeEnabled { - mi := &file_storage_proto_msgTypes[7] + mi := &file_storage_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -402,7 +496,7 @@ func (x *PurgeRequest) String() string { func (*PurgeRequest) ProtoMessage() {} func (x *PurgeRequest) ProtoReflect() protoreflect.Message { - mi := &file_storage_proto_msgTypes[7] + mi := &file_storage_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -415,7 +509,7 @@ func (x *PurgeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PurgeRequest.ProtoReflect.Descriptor instead. func (*PurgeRequest) Descriptor() ([]byte, []int) { - return file_storage_proto_rawDescGZIP(), []int{7} + return file_storage_proto_rawDescGZIP(), []int{9} } type PurgeReply struct { @@ -427,7 +521,7 @@ type PurgeReply struct { func (x *PurgeReply) Reset() { *x = PurgeReply{} if protoimpl.UnsafeEnabled { - mi := &file_storage_proto_msgTypes[8] + mi := &file_storage_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -440,7 +534,7 @@ func (x *PurgeReply) String() string { func (*PurgeReply) ProtoMessage() {} func (x *PurgeReply) ProtoReflect() protoreflect.Message { - mi := &file_storage_proto_msgTypes[8] + mi := &file_storage_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -453,7 +547,7 @@ func (x *PurgeReply) ProtoReflect() protoreflect.Message { // Deprecated: Use PurgeReply.ProtoReflect.Descriptor instead. func (*PurgeReply) Descriptor() ([]byte, []int) { - return file_storage_proto_rawDescGZIP(), []int{8} + return file_storage_proto_rawDescGZIP(), []int{10} } var File_storage_proto protoreflect.FileDescriptor @@ -477,31 +571,39 @@ var file_storage_proto_rawDesc = []byte{ 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x69, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x61, 0x70, 0x69, 0x22, 0x20, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, 0x37, 0x0a, 0x09, 0x47, 0x65, - 0x74, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x72, - 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, - 0x75, 0x6c, 0x74, 0x22, 0x0c, 0x0a, 0x0a, 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x22, 0x23, 0x0a, 0x09, 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x12, 0x16, - 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, - 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0x0e, 0x0a, 0x0c, 0x50, 0x75, 0x72, 0x67, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x0c, 0x0a, 0x0a, 0x50, 0x75, 0x72, 0x67, 0x65, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x32, 0xdb, 0x01, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, - 0x12, 0x35, 0x0a, 0x05, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x12, 0x15, 0x2e, 0x73, 0x74, 0x6f, 0x72, - 0x61, 0x67, 0x65, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x13, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, - 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x30, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x13, - 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, - 0x74, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x00, 0x12, 0x30, 0x0a, 0x03, 0x4c, 0x65, 0x6e, - 0x12, 0x13, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x65, 0x6e, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, - 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x05, 0x50, - 0x75, 0x72, 0x67, 0x65, 0x12, 0x15, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x50, - 0x75, 0x72, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x73, 0x74, - 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x75, 0x72, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x22, 0x00, 0x42, 0x0d, 0x50, 0x01, 0x5a, 0x09, 0x2e, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, - 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, 0x23, 0x0a, 0x0d, 0x52, 0x65, + 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x68, + 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, + 0x37, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x12, 0x12, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x25, 0x0a, 0x0b, 0x52, 0x65, 0x6d, 0x6f, + 0x76, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, + 0x0c, 0x0a, 0x0a, 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x23, 0x0a, + 0x09, 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, + 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, + 0x74, 0x68, 0x22, 0x0e, 0x0a, 0x0c, 0x50, 0x75, 0x72, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x22, 0x0c, 0x0a, 0x0a, 0x50, 0x75, 0x72, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x32, 0x95, 0x02, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x12, 0x35, 0x0a, 0x05, + 0x53, 0x74, 0x6f, 0x72, 0x65, 0x12, 0x15, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, + 0x53, 0x74, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x73, + 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x00, 0x12, 0x30, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x13, 0x2e, 0x73, 0x74, 0x6f, + 0x72, 0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x12, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x70, + 0x6c, 0x61, 0x79, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, + 0x16, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, + 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, + 0x30, 0x0a, 0x03, 0x4c, 0x65, 0x6e, 0x12, 0x13, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, + 0x2e, 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73, 0x74, + 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x65, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x22, + 0x00, 0x12, 0x35, 0x0a, 0x05, 0x50, 0x75, 0x72, 0x67, 0x65, 0x12, 0x15, 0x2e, 0x73, 0x74, 0x6f, + 0x72, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x75, 0x72, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x13, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x75, 0x72, 0x67, + 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0d, 0x50, 0x01, 0x5a, 0x09, 0x2e, 0x3b, + 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -516,35 +618,39 @@ func file_storage_proto_rawDescGZIP() []byte { return file_storage_proto_rawDescData } -var file_storage_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_storage_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_storage_proto_goTypes = []interface{}{ (*Page)(nil), // 0: storage.Page (*StoreRequest)(nil), // 1: storage.StoreRequest (*StoreReply)(nil), // 2: storage.StoreReply (*GetRequest)(nil), // 3: storage.GetRequest - (*GetReplay)(nil), // 4: storage.GetReplay - (*LenRequest)(nil), // 5: storage.LenRequest - (*LenReplay)(nil), // 6: storage.LenReplay - (*PurgeRequest)(nil), // 7: storage.PurgeRequest - (*PurgeReply)(nil), // 8: storage.PurgeReply - (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp + (*RemoveRequest)(nil), // 4: storage.RemoveRequest + (*GetReplay)(nil), // 5: storage.GetReplay + (*RemoveReply)(nil), // 6: storage.RemoveReply + (*LenRequest)(nil), // 7: storage.LenRequest + (*LenReplay)(nil), // 8: storage.LenReplay + (*PurgeRequest)(nil), // 9: storage.PurgeRequest + (*PurgeReply)(nil), // 10: storage.PurgeReply + (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp } var file_storage_proto_depIdxs = []int32{ - 9, // 0: storage.Page.createdAt:type_name -> google.protobuf.Timestamp - 0, // 1: storage.StoreRequest.page:type_name -> storage.Page - 1, // 2: storage.Storage.Store:input_type -> storage.StoreRequest - 3, // 3: storage.Storage.Get:input_type -> storage.GetRequest - 5, // 4: storage.Storage.Len:input_type -> storage.LenRequest - 7, // 5: storage.Storage.Purge:input_type -> storage.PurgeRequest - 2, // 6: storage.Storage.Store:output_type -> storage.StoreReply - 4, // 7: storage.Storage.Get:output_type -> storage.GetReplay - 6, // 8: storage.Storage.Len:output_type -> storage.LenReplay - 8, // 9: storage.Storage.Purge:output_type -> storage.PurgeReply - 6, // [6:10] is the sub-list for method output_type - 2, // [2:6] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 11, // 0: storage.Page.createdAt:type_name -> google.protobuf.Timestamp + 0, // 1: storage.StoreRequest.page:type_name -> storage.Page + 1, // 2: storage.Storage.Store:input_type -> storage.StoreRequest + 3, // 3: storage.Storage.Get:input_type -> storage.GetRequest + 4, // 4: storage.Storage.Remove:input_type -> storage.RemoveRequest + 7, // 5: storage.Storage.Len:input_type -> storage.LenRequest + 9, // 6: storage.Storage.Purge:input_type -> storage.PurgeRequest + 2, // 7: storage.Storage.Store:output_type -> storage.StoreReply + 5, // 8: storage.Storage.Get:output_type -> storage.GetReplay + 6, // 9: storage.Storage.Remove:output_type -> storage.RemoveReply + 8, // 10: storage.Storage.Len:output_type -> storage.LenReplay + 10, // 11: storage.Storage.Purge:output_type -> storage.PurgeReply + 7, // [7:12] is the sub-list for method output_type + 2, // [2:7] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_storage_proto_init() } @@ -602,7 +708,7 @@ func file_storage_proto_init() { } } file_storage_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetReplay); i { + switch v := v.(*RemoveRequest); i { case 0: return &v.state case 1: @@ -614,7 +720,7 @@ func file_storage_proto_init() { } } file_storage_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LenRequest); i { + switch v := v.(*GetReplay); i { case 0: return &v.state case 1: @@ -626,7 +732,7 @@ func file_storage_proto_init() { } } file_storage_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LenReplay); i { + switch v := v.(*RemoveReply); i { case 0: return &v.state case 1: @@ -638,7 +744,7 @@ func file_storage_proto_init() { } } file_storage_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PurgeRequest); i { + switch v := v.(*LenRequest); i { case 0: return &v.state case 1: @@ -650,6 +756,30 @@ func file_storage_proto_init() { } } file_storage_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LenReplay); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_storage_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PurgeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_storage_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PurgeReply); i { case 0: return &v.state @@ -668,7 +798,7 @@ func file_storage_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_storage_proto_rawDesc, NumEnums: 0, - NumMessages: 9, + NumMessages: 11, NumExtensions: 0, NumServices: 1, }, diff --git a/src/pkg/api/storage/storage_grpc.pb.go b/src/pkg/api/storage/storage_grpc.pb.go index 0a85af6..e8a7d51 100644 --- a/src/pkg/api/storage/storage_grpc.pb.go +++ b/src/pkg/api/storage/storage_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.19.4 +// - protoc v3.20.1 // source: storage.proto package storage @@ -27,6 +27,8 @@ type StorageClient interface { // Get a request from storage Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetReplay, error) // + Remove(ctx context.Context, in *RemoveRequest, opts ...grpc.CallOption) (*RemoveReply, error) + // Len(ctx context.Context, in *LenRequest, opts ...grpc.CallOption) (*LenReplay, error) // Purge(ctx context.Context, in *PurgeRequest, opts ...grpc.CallOption) (*PurgeReply, error) @@ -58,6 +60,15 @@ func (c *storageClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.Ca return out, nil } +func (c *storageClient) Remove(ctx context.Context, in *RemoveRequest, opts ...grpc.CallOption) (*RemoveReply, error) { + out := new(RemoveReply) + err := c.cc.Invoke(ctx, "/storage.Storage/Remove", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *storageClient) Len(ctx context.Context, in *LenRequest, opts ...grpc.CallOption) (*LenReplay, error) { out := new(LenReplay) err := c.cc.Invoke(ctx, "/storage.Storage/Len", in, out, opts...) @@ -85,6 +96,8 @@ type StorageServer interface { // Get a request from storage Get(context.Context, *GetRequest) (*GetReplay, error) // + Remove(context.Context, *RemoveRequest) (*RemoveReply, error) + // Len(context.Context, *LenRequest) (*LenReplay, error) // Purge(context.Context, *PurgeRequest) (*PurgeReply, error) @@ -101,6 +114,9 @@ func (UnimplementedStorageServer) Store(context.Context, *StoreRequest) (*StoreR func (UnimplementedStorageServer) Get(context.Context, *GetRequest) (*GetReplay, error) { return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") } +func (UnimplementedStorageServer) Remove(context.Context, *RemoveRequest) (*RemoveReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Remove not implemented") +} func (UnimplementedStorageServer) Len(context.Context, *LenRequest) (*LenReplay, error) { return nil, status.Errorf(codes.Unimplemented, "method Len not implemented") } @@ -156,6 +172,24 @@ func _Storage_Get_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } +func _Storage_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RemoveRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StorageServer).Remove(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/storage.Storage/Remove", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StorageServer).Remove(ctx, req.(*RemoveRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Storage_Len_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(LenRequest) if err := dec(in); err != nil { @@ -207,6 +241,10 @@ var Storage_ServiceDesc = grpc.ServiceDesc{ MethodName: "Get", Handler: _Storage_Get_Handler, }, + { + MethodName: "Remove", + Handler: _Storage_Remove_Handler, + }, { MethodName: "Len", Handler: _Storage_Len_Handler,