diff --git a/file/.gitignore b/file/.gitignore new file mode 100644 index 0000000..ee87418 --- /dev/null +++ b/file/.gitignore @@ -0,0 +1,2 @@ + +file diff --git a/file/Dockerfile b/file/Dockerfile new file mode 100644 index 0000000..0f3519a --- /dev/null +++ b/file/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +ADD file /file +ENTRYPOINT [ "/file" ] diff --git a/files/Makefile b/file/Makefile similarity index 68% rename from files/Makefile rename to file/Makefile index 2559915..17fd947 100644 --- a/files/Makefile +++ b/file/Makefile @@ -8,15 +8,15 @@ init: go get github.com/micro/micro/v3/cmd/protoc-gen-openapi .PHONY: proto proto: - protoc --proto_path=. --micro_out=. --go_out=:. proto/files.proto + protoc --proto_path=. --micro_out=. --go_out=:. proto/file.proto .PHONY: api api: - protoc --openapi_out=. --proto_path=. proto/files.proto + protoc --openapi_out=. --proto_path=. proto/file.proto .PHONY: build build: - go build -o files *.go + go build -o file *.go .PHONY: test test: @@ -24,4 +24,4 @@ test: .PHONY: docker docker: - docker build . -t files:latest + docker build . -t file:latest diff --git a/file/README.md b/file/README.md new file mode 100644 index 0000000..7eb6432 --- /dev/null +++ b/file/README.md @@ -0,0 +1,5 @@ +Store, list and retrieve text file + +# File Service + +Save, list and retrieve text file by project and path. diff --git a/files/generate.go b/file/generate.go similarity index 100% rename from files/generate.go rename to file/generate.go diff --git a/files/handler/files.go b/file/handler/files.go similarity index 64% rename from files/handler/files.go rename to file/handler/files.go index a1f02ae..2bd1af8 100644 --- a/files/handler/files.go +++ b/file/handler/files.go @@ -8,41 +8,41 @@ import ( "github.com/micro/micro/v3/service/auth" log "github.com/micro/micro/v3/service/logger" "github.com/micro/micro/v3/service/model" - files "github.com/micro/services/files/proto" + file "github.com/micro/services/file/proto" ) -type Files struct { +type File struct { db model.Model } -func NewFiles() *Files { +func NewFile() *File { i := model.ByEquality("project") i.Order.Type = model.OrderTypeUnordered db := model.New( - files.File{}, + file.Record{}, &model.Options{ Key: "Id", Indexes: []model.Index{i}, }, ) - return &Files{ + return &File{ db: db, } } -func (e *Files) Save(ctx context.Context, req *files.SaveRequest, rsp *files.SaveResponse) error { +func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveResponse) error { // @todo return proper micro errors acc, ok := auth.AccountFromContext(ctx) if !ok { - return errors.New("Files.Save requires authentication") + return errors.New("File.Save requires authentication") } - log.Info("Received Files.Save request") - for _, file := range req.Files { - f := files.File{} - err := e.db.Read(model.QueryEquals("Id", file.Id), &f) + log.Info("Received File.Save request") + for _, reqFile := range req.Files { + f := file.Record{} + err := e.db.Read(model.QueryEquals("Id", reqFile.Id), &f) if err != nil && err != model.ErrorNotFound { return err } @@ -50,7 +50,7 @@ func (e *Files) Save(ctx context.Context, req *files.SaveRequest, rsp *files.Sav if f.Id != "" && f.Owner != acc.ID { return errors.New("Not authorized") } - err = e.db.Create(file) + err = e.db.Create(reqFile) if err != nil { return err } @@ -58,9 +58,9 @@ func (e *Files) Save(ctx context.Context, req *files.SaveRequest, rsp *files.Sav return nil } -func (e *Files) List(ctx context.Context, req *files.ListRequest, rsp *files.ListResponse) error { - log.Info("Received Files.List request") - rsp.Files = []*files.File{} +func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListResponse) error { + log.Info("Received File.List request") + rsp.Files = []*file.Record{} err := e.db.Read(model.QueryEquals("project", req.GetProject()), &rsp.Files) if err != nil { return err @@ -69,7 +69,7 @@ func (e *Files) List(ctx context.Context, req *files.ListRequest, rsp *files.Lis // query for the KV store interface, it's not supported by the model // so we do client side filtering here if req.Path != "" { - filtered := []*files.File{} + filtered := []*file.Record{} for _, file := range rsp.Files { if strings.HasPrefix(file.Path, req.Path) { filtered = append(filtered, file) diff --git a/files/main.go b/file/main.go similarity index 63% rename from files/main.go rename to file/main.go index cadc0cb..a62fea8 100644 --- a/files/main.go +++ b/file/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/micro/services/files/handler" - pb "github.com/micro/services/files/proto" + "github.com/micro/services/file/handler" + pb "github.com/micro/services/file/proto" "github.com/micro/micro/v3/service" "github.com/micro/micro/v3/service/logger" @@ -11,12 +11,12 @@ import ( func main() { // Create service srv := service.New( - service.Name("files"), + service.Name("file"), service.Version("latest"), ) // Register handler - pb.RegisterFilesHandler(srv.Server(), handler.NewFiles()) + pb.RegisterFileHandler(srv.Server(), handler.NewFile()) // Run service if err := srv.Run(); err != nil { diff --git a/file/micro.mu b/file/micro.mu new file mode 100644 index 0000000..68c3a2b --- /dev/null +++ b/file/micro.mu @@ -0,0 +1 @@ +service file diff --git a/files/proto/files.pb.go b/file/proto/file.pb.go similarity index 58% rename from files/proto/files.pb.go rename to file/proto/file.pb.go index e5f538f..7204e86 100644 --- a/files/proto/files.pb.go +++ b/file/proto/file.pb.go @@ -1,13 +1,12 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.5 -// source: proto/files.proto +// protoc-gen-go v1.26.0 +// protoc v3.6.1 +// source: proto/file.proto -package files +package file import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -21,18 +20,14 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -type File struct { +type Record struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // A custom string for namespacing purposes - // eg. files-of-mywebsite.com + // eg. file-of-mywebsite.com Project string `protobuf:"bytes,2,opt,name=project,proto3" json:"project,omitempty"` // Name of folder or file. Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` @@ -47,23 +42,23 @@ type File struct { Owner string `protobuf:"bytes,9,opt,name=owner,proto3" json:"owner,omitempty"` } -func (x *File) Reset() { - *x = File{} +func (x *Record) Reset() { + *x = Record{} if protoimpl.UnsafeEnabled { - mi := &file_proto_files_proto_msgTypes[0] + mi := &file_proto_file_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *File) String() string { +func (x *Record) String() string { return protoimpl.X.MessageStringOf(x) } -func (*File) ProtoMessage() {} +func (*Record) ProtoMessage() {} -func (x *File) ProtoReflect() protoreflect.Message { - mi := &file_proto_files_proto_msgTypes[0] +func (x *Record) ProtoReflect() protoreflect.Message { + mi := &file_proto_file_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -74,87 +69,87 @@ func (x *File) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use File.ProtoReflect.Descriptor instead. -func (*File) Descriptor() ([]byte, []int) { - return file_proto_files_proto_rawDescGZIP(), []int{0} +// Deprecated: Use Record.ProtoReflect.Descriptor instead. +func (*Record) Descriptor() ([]byte, []int) { + return file_proto_file_proto_rawDescGZIP(), []int{0} } -func (x *File) GetId() string { +func (x *Record) GetId() string { if x != nil { return x.Id } return "" } -func (x *File) GetProject() string { +func (x *Record) GetProject() string { if x != nil { return x.Project } return "" } -func (x *File) GetName() string { +func (x *Record) GetName() string { if x != nil { return x.Name } return "" } -func (x *File) GetPath() string { +func (x *Record) GetPath() string { if x != nil { return x.Path } return "" } -func (x *File) GetIsDirectory() bool { +func (x *Record) GetIsDirectory() bool { if x != nil { return x.IsDirectory } return false } -func (x *File) GetFileContents() string { +func (x *Record) GetFileContents() string { if x != nil { return x.FileContents } return "" } -func (x *File) GetCreated() int64 { +func (x *Record) GetCreated() int64 { if x != nil { return x.Created } return 0 } -func (x *File) GetUpdated() int64 { +func (x *Record) GetUpdated() int64 { if x != nil { return x.Updated } return 0 } -func (x *File) GetOwner() string { +func (x *Record) GetOwner() string { if x != nil { return x.Owner } return "" } -// The save endpoint lets you batch save text files. +// The save endpoint lets you batch save text file. type SaveRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Files []*File `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"` + Files []*Record `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"` } func (x *SaveRequest) Reset() { *x = SaveRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_files_proto_msgTypes[1] + mi := &file_proto_file_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -167,7 +162,7 @@ func (x *SaveRequest) String() string { func (*SaveRequest) ProtoMessage() {} func (x *SaveRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_files_proto_msgTypes[1] + mi := &file_proto_file_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -180,10 +175,10 @@ func (x *SaveRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SaveRequest.ProtoReflect.Descriptor instead. func (*SaveRequest) Descriptor() ([]byte, []int) { - return file_proto_files_proto_rawDescGZIP(), []int{1} + return file_proto_file_proto_rawDescGZIP(), []int{1} } -func (x *SaveRequest) GetFiles() []*File { +func (x *SaveRequest) GetFiles() []*Record { if x != nil { return x.Files } @@ -199,7 +194,7 @@ type SaveResponse struct { func (x *SaveResponse) Reset() { *x = SaveResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_files_proto_msgTypes[2] + mi := &file_proto_file_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -212,7 +207,7 @@ func (x *SaveResponse) String() string { func (*SaveResponse) ProtoMessage() {} func (x *SaveResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_files_proto_msgTypes[2] + mi := &file_proto_file_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -225,10 +220,10 @@ func (x *SaveResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use SaveResponse.ProtoReflect.Descriptor instead. func (*SaveResponse) Descriptor() ([]byte, []int) { - return file_proto_files_proto_rawDescGZIP(), []int{2} + return file_proto_file_proto_rawDescGZIP(), []int{2} } -// List files by their project and optionally a path. +// List file by their project and optionally a path. type ListRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -238,7 +233,7 @@ type ListRequest struct { Project string `protobuf:"bytes,1,opt,name=project,proto3" json:"project,omitempty"` // Defaults to '/', ie. lists all files in a project. // Supply path if of a folder if you want to list - // file inside that folder + // files inside that folder // eg. '/docs' Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` } @@ -246,7 +241,7 @@ type ListRequest struct { func (x *ListRequest) Reset() { *x = ListRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_files_proto_msgTypes[3] + mi := &file_proto_file_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -259,7 +254,7 @@ func (x *ListRequest) String() string { func (*ListRequest) ProtoMessage() {} func (x *ListRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_files_proto_msgTypes[3] + mi := &file_proto_file_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -272,7 +267,7 @@ func (x *ListRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListRequest.ProtoReflect.Descriptor instead. func (*ListRequest) Descriptor() ([]byte, []int) { - return file_proto_files_proto_rawDescGZIP(), []int{3} + return file_proto_file_proto_rawDescGZIP(), []int{3} } func (x *ListRequest) GetProject() string { @@ -294,13 +289,13 @@ type ListResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Files []*File `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"` + Files []*Record `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"` } func (x *ListResponse) Reset() { *x = ListResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_files_proto_msgTypes[4] + mi := &file_proto_file_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -313,7 +308,7 @@ func (x *ListResponse) String() string { func (*ListResponse) ProtoMessage() {} func (x *ListResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_files_proto_msgTypes[4] + mi := &file_proto_file_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -326,22 +321,22 @@ func (x *ListResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListResponse.ProtoReflect.Descriptor instead. func (*ListResponse) Descriptor() ([]byte, []int) { - return file_proto_files_proto_rawDescGZIP(), []int{4} + return file_proto_file_proto_rawDescGZIP(), []int{4} } -func (x *ListResponse) GetFiles() []*File { +func (x *ListResponse) GetFiles() []*Record { if x != nil { return x.Files } return nil } -var File_proto_files_proto protoreflect.FileDescriptor +var File_proto_file_proto protoreflect.FileDescriptor -var file_proto_files_proto_rawDesc = []byte{ - 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0xea, 0x01, 0x0a, 0x04, 0x46, - 0x69, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, +var file_proto_file_proto_rawDesc = []byte{ + 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0xec, 0x01, 0x0a, 0x06, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, @@ -355,55 +350,55 @@ var file_proto_files_proto_rawDesc = []byte{ 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x0b, 0x53, 0x61, 0x76, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, - 0x6c, 0x65, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x0e, 0x0a, 0x0c, 0x53, 0x61, 0x76, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3b, 0x0a, 0x0b, 0x4c, 0x69, 0x73, - 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x31, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, - 0x6c, 0x65, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x32, 0x6d, 0x0a, 0x05, 0x46, 0x69, 0x6c, - 0x65, 0x73, 0x12, 0x31, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x12, 0x2e, 0x66, 0x69, 0x6c, - 0x65, 0x73, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, - 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x12, 0x2e, - 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x13, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x3b, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x31, 0x0a, 0x0b, 0x53, 0x61, 0x76, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x0e, 0x0a, 0x0c, 0x53, 0x61, + 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3b, 0x0a, 0x0b, 0x4c, 0x69, + 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, + 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, + 0x65, 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x32, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, + 0x63, 0x6f, 0x72, 0x64, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x32, 0x68, 0x0a, 0x04, 0x46, + 0x69, 0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x11, 0x2e, 0x66, 0x69, + 0x6c, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, + 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x66, + 0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x3b, 0x66, 0x69, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_proto_files_proto_rawDescOnce sync.Once - file_proto_files_proto_rawDescData = file_proto_files_proto_rawDesc + file_proto_file_proto_rawDescOnce sync.Once + file_proto_file_proto_rawDescData = file_proto_file_proto_rawDesc ) -func file_proto_files_proto_rawDescGZIP() []byte { - file_proto_files_proto_rawDescOnce.Do(func() { - file_proto_files_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_files_proto_rawDescData) +func file_proto_file_proto_rawDescGZIP() []byte { + file_proto_file_proto_rawDescOnce.Do(func() { + file_proto_file_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_file_proto_rawDescData) }) - return file_proto_files_proto_rawDescData + return file_proto_file_proto_rawDescData } -var file_proto_files_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_proto_files_proto_goTypes = []interface{}{ - (*File)(nil), // 0: files.File - (*SaveRequest)(nil), // 1: files.SaveRequest - (*SaveResponse)(nil), // 2: files.SaveResponse - (*ListRequest)(nil), // 3: files.ListRequest - (*ListResponse)(nil), // 4: files.ListResponse +var file_proto_file_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_proto_file_proto_goTypes = []interface{}{ + (*Record)(nil), // 0: file.Record + (*SaveRequest)(nil), // 1: file.SaveRequest + (*SaveResponse)(nil), // 2: file.SaveResponse + (*ListRequest)(nil), // 3: file.ListRequest + (*ListResponse)(nil), // 4: file.ListResponse } -var file_proto_files_proto_depIdxs = []int32{ - 0, // 0: files.SaveRequest.files:type_name -> files.File - 0, // 1: files.ListResponse.files:type_name -> files.File - 1, // 2: files.Files.Save:input_type -> files.SaveRequest - 3, // 3: files.Files.List:input_type -> files.ListRequest - 2, // 4: files.Files.Save:output_type -> files.SaveResponse - 4, // 5: files.Files.List:output_type -> files.ListResponse +var file_proto_file_proto_depIdxs = []int32{ + 0, // 0: file.SaveRequest.files:type_name -> file.Record + 0, // 1: file.ListResponse.files:type_name -> file.Record + 1, // 2: file.File.Save:input_type -> file.SaveRequest + 3, // 3: file.File.List:input_type -> file.ListRequest + 2, // 4: file.File.Save:output_type -> file.SaveResponse + 4, // 5: file.File.List:output_type -> file.ListResponse 4, // [4:6] is the sub-list for method output_type 2, // [2:4] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name @@ -411,14 +406,14 @@ var file_proto_files_proto_depIdxs = []int32{ 0, // [0:2] is the sub-list for field type_name } -func init() { file_proto_files_proto_init() } -func file_proto_files_proto_init() { - if File_proto_files_proto != nil { +func init() { file_proto_file_proto_init() } +func file_proto_file_proto_init() { + if File_proto_file_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proto_files_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*File); i { + file_proto_file_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Record); i { case 0: return &v.state case 1: @@ -429,7 +424,7 @@ func file_proto_files_proto_init() { return nil } } - file_proto_files_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_proto_file_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SaveRequest); i { case 0: return &v.state @@ -441,7 +436,7 @@ func file_proto_files_proto_init() { return nil } } - file_proto_files_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_proto_file_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SaveResponse); i { case 0: return &v.state @@ -453,7 +448,7 @@ func file_proto_files_proto_init() { return nil } } - file_proto_files_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_proto_file_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListRequest); i { case 0: return &v.state @@ -465,7 +460,7 @@ func file_proto_files_proto_init() { return nil } } - file_proto_files_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_proto_file_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListResponse); i { case 0: return &v.state @@ -482,18 +477,18 @@ func file_proto_files_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_files_proto_rawDesc, + RawDescriptor: file_proto_file_proto_rawDesc, NumEnums: 0, NumMessages: 5, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_proto_files_proto_goTypes, - DependencyIndexes: file_proto_files_proto_depIdxs, - MessageInfos: file_proto_files_proto_msgTypes, + GoTypes: file_proto_file_proto_goTypes, + DependencyIndexes: file_proto_file_proto_depIdxs, + MessageInfos: file_proto_file_proto_msgTypes, }.Build() - File_proto_files_proto = out.File - file_proto_files_proto_rawDesc = nil - file_proto_files_proto_goTypes = nil - file_proto_files_proto_depIdxs = nil + File_proto_file_proto = out.File + file_proto_file_proto_rawDesc = nil + file_proto_file_proto_goTypes = nil + file_proto_file_proto_depIdxs = nil } diff --git a/files/proto/files.pb.micro.go b/file/proto/file.pb.micro.go similarity index 58% rename from files/proto/files.pb.micro.go rename to file/proto/file.pb.micro.go index 38e2ba6..770cd79 100644 --- a/files/proto/files.pb.micro.go +++ b/file/proto/file.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: proto/files.proto +// source: proto/file.proto -package files +package file import ( fmt "fmt" @@ -33,33 +33,33 @@ var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Files service +// Api Endpoints for File service -func NewFilesEndpoints() []*api.Endpoint { +func NewFileEndpoints() []*api.Endpoint { return []*api.Endpoint{} } -// Client API for Files service +// Client API for File service -type FilesService interface { +type FileService interface { Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) } -type filesService struct { +type fileService struct { c client.Client name string } -func NewFilesService(name string, c client.Client) FilesService { - return &filesService{ +func NewFileService(name string, c client.Client) FileService { + return &fileService{ c: c, name: name, } } -func (c *filesService) Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error) { - req := c.c.NewRequest(c.name, "Files.Save", in) +func (c *fileService) Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error) { + req := c.c.NewRequest(c.name, "File.Save", in) out := new(SaveResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -68,8 +68,8 @@ func (c *filesService) Save(ctx context.Context, in *SaveRequest, opts ...client return out, nil } -func (c *filesService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { - req := c.c.NewRequest(c.name, "Files.List", in) +func (c *fileService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "File.List", in) out := new(ListResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -78,33 +78,33 @@ func (c *filesService) List(ctx context.Context, in *ListRequest, opts ...client return out, nil } -// Server API for Files service +// Server API for File service -type FilesHandler interface { +type FileHandler interface { Save(context.Context, *SaveRequest, *SaveResponse) error List(context.Context, *ListRequest, *ListResponse) error } -func RegisterFilesHandler(s server.Server, hdlr FilesHandler, opts ...server.HandlerOption) error { - type files interface { +func RegisterFileHandler(s server.Server, hdlr FileHandler, opts ...server.HandlerOption) error { + type file interface { Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error List(ctx context.Context, in *ListRequest, out *ListResponse) error } - type Files struct { - files + type File struct { + file } - h := &filesHandler{hdlr} - return s.Handle(s.NewHandler(&Files{h}, opts...)) + h := &fileHandler{hdlr} + return s.Handle(s.NewHandler(&File{h}, opts...)) } -type filesHandler struct { - FilesHandler +type fileHandler struct { + FileHandler } -func (h *filesHandler) Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error { - return h.FilesHandler.Save(ctx, in, out) +func (h *fileHandler) Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error { + return h.FileHandler.Save(ctx, in, out) } -func (h *filesHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { - return h.FilesHandler.List(ctx, in, out) +func (h *fileHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.FileHandler.List(ctx, in, out) } diff --git a/files/proto/files.proto b/file/proto/file.proto similarity index 71% rename from files/proto/files.proto rename to file/proto/file.proto index 2c0a3c5..a68828c 100644 --- a/files/proto/files.proto +++ b/file/proto/file.proto @@ -1,18 +1,18 @@ syntax = "proto3"; -package files; +package file; -option go_package = "./proto;files"; +option go_package = "./proto;file"; -service Files { +service File { rpc Save(SaveRequest) returns (SaveResponse) {} rpc List(ListRequest) returns (ListResponse) {} } -message File { +message Record { string id = 1; // A custom string for namespacing purposes - // eg. files-of-mywebsite.com + // eg. file-of-mywebsite.com string project = 2; // Name of folder or file. string name = 3; @@ -27,25 +27,25 @@ message File { string owner = 9; } -// The save endpoint lets you batch save text files. +// The save endpoint lets you batch save text file. message SaveRequest { - repeated File files = 1; + repeated Record files = 1; } message SaveResponse { } -// List files by their project and optionally a path. +// List file by their project and optionally a path. message ListRequest { // Project, required for listing. string project = 1; // Defaults to '/', ie. lists all files in a project. // Supply path if of a folder if you want to list - // file inside that folder + // files inside that folder // eg. '/docs' string path = 2; } message ListResponse { - repeated File files = 1; + repeated Record files = 1; } diff --git a/files/.gitignore b/files/.gitignore deleted file mode 100644 index 6908902..0000000 --- a/files/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ - -files diff --git a/files/Dockerfile b/files/Dockerfile deleted file mode 100644 index 8387247..0000000 --- a/files/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM alpine -ADD files /files -ENTRYPOINT [ "/files" ] diff --git a/files/README.md b/files/README.md deleted file mode 100644 index 6ccdeae..0000000 --- a/files/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Store, list and retrieve text files - -# Files Service - -Save, list and retrieve text files by project and path. diff --git a/files/micro.mu b/files/micro.mu deleted file mode 100644 index 3923b39..0000000 --- a/files/micro.mu +++ /dev/null @@ -1 +0,0 @@ -service files