Rename files service to file service (#115)

This commit is contained in:
Janos Dobronszki
2021-05-19 16:53:42 +01:00
committed by GitHub
parent 17cd2399c8
commit 90186703f9
15 changed files with 178 additions and 183 deletions

2
file/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
file

3
file/Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM alpine
ADD file /file
ENTRYPOINT [ "/file" ]

27
file/Makefile Normal file
View File

@@ -0,0 +1,27 @@
GOPATH:=$(shell go env GOPATH)
.PHONY: init
init:
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
go get github.com/micro/micro/v3/cmd/protoc-gen-openapi
.PHONY: proto
proto:
protoc --proto_path=. --micro_out=. --go_out=:. proto/file.proto
.PHONY: api
api:
protoc --openapi_out=. --proto_path=. proto/file.proto
.PHONY: build
build:
go build -o file *.go
.PHONY: test
test:
go test -v ./... -cover
.PHONY: docker
docker:
docker build . -t file:latest

5
file/README.md Normal file
View File

@@ -0,0 +1,5 @@
Store, list and retrieve text file
# File Service
Save, list and retrieve text file by project and path.

3
file/generate.go Normal file
View File

@@ -0,0 +1,3 @@
package main
//go:generate make proto

81
file/handler/files.go Normal file
View File

@@ -0,0 +1,81 @@
package handler
import (
"context"
"errors"
"strings"
"github.com/micro/micro/v3/service/auth"
log "github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/model"
file "github.com/micro/services/file/proto"
)
type File struct {
db model.Model
}
func NewFile() *File {
i := model.ByEquality("project")
i.Order.Type = model.OrderTypeUnordered
db := model.New(
file.Record{},
&model.Options{
Key: "Id",
Indexes: []model.Index{i},
},
)
return &File{
db: db,
}
}
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("File.Save requires authentication")
}
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
}
// if file exists check ownership
if f.Id != "" && f.Owner != acc.ID {
return errors.New("Not authorized")
}
err = e.db.Create(reqFile)
if err != nil {
return err
}
}
return nil
}
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
}
// @todo funnily while this is the archetypical
// query for the KV store interface, it's not supported by the model
// so we do client side filtering here
if req.Path != "" {
filtered := []*file.Record{}
for _, file := range rsp.Files {
if strings.HasPrefix(file.Path, req.Path) {
filtered = append(filtered, file)
}
}
rsp.Files = filtered
}
return nil
}

25
file/main.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"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"
)
func main() {
// Create service
srv := service.New(
service.Name("file"),
service.Version("latest"),
)
// Register handler
pb.RegisterFileHandler(srv.Server(), handler.NewFile())
// Run service
if err := srv.Run(); err != nil {
logger.Fatal(err)
}
}

1
file/micro.mu Normal file
View File

@@ -0,0 +1 @@
service file

494
file/proto/file.pb.go Normal file
View File

@@ -0,0 +1,494 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.6.1
// source: proto/file.proto
package file
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
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. 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"`
// Path. Default is '/', ie. top level
Path string `protobuf:"bytes,4,opt,name=path,proto3" json:"path,omitempty"`
IsDirectory bool `protobuf:"varint,5,opt,name=is_directory,json=isDirectory,proto3" json:"is_directory,omitempty"`
// File contents. Empty for directories.
FileContents string `protobuf:"bytes,6,opt,name=file_contents,json=fileContents,proto3" json:"file_contents,omitempty"`
Created int64 `protobuf:"varint,7,opt,name=created,proto3" json:"created,omitempty"`
Updated int64 `protobuf:"varint,8,opt,name=updated,proto3" json:"updated,omitempty"`
// owner
Owner string `protobuf:"bytes,9,opt,name=owner,proto3" json:"owner,omitempty"`
}
func (x *Record) Reset() {
*x = Record{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_file_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Record) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Record) ProtoMessage() {}
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 {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Record.ProtoReflect.Descriptor instead.
func (*Record) Descriptor() ([]byte, []int) {
return file_proto_file_proto_rawDescGZIP(), []int{0}
}
func (x *Record) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Record) GetProject() string {
if x != nil {
return x.Project
}
return ""
}
func (x *Record) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Record) GetPath() string {
if x != nil {
return x.Path
}
return ""
}
func (x *Record) GetIsDirectory() bool {
if x != nil {
return x.IsDirectory
}
return false
}
func (x *Record) GetFileContents() string {
if x != nil {
return x.FileContents
}
return ""
}
func (x *Record) GetCreated() int64 {
if x != nil {
return x.Created
}
return 0
}
func (x *Record) GetUpdated() int64 {
if x != nil {
return x.Updated
}
return 0
}
func (x *Record) GetOwner() string {
if x != nil {
return x.Owner
}
return ""
}
// The save endpoint lets you batch save text file.
type SaveRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Files []*Record `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"`
}
func (x *SaveRequest) Reset() {
*x = SaveRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_file_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SaveRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SaveRequest) ProtoMessage() {}
func (x *SaveRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_file_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SaveRequest.ProtoReflect.Descriptor instead.
func (*SaveRequest) Descriptor() ([]byte, []int) {
return file_proto_file_proto_rawDescGZIP(), []int{1}
}
func (x *SaveRequest) GetFiles() []*Record {
if x != nil {
return x.Files
}
return nil
}
type SaveResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *SaveResponse) Reset() {
*x = SaveResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_file_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SaveResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SaveResponse) ProtoMessage() {}
func (x *SaveResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_file_proto_msgTypes[2]
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 SaveResponse.ProtoReflect.Descriptor instead.
func (*SaveResponse) Descriptor() ([]byte, []int) {
return file_proto_file_proto_rawDescGZIP(), []int{2}
}
// List file by their project and optionally a path.
type ListRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Project, required for listing.
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
// files inside that folder
// eg. '/docs'
Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
}
func (x *ListRequest) Reset() {
*x = ListRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_file_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListRequest) ProtoMessage() {}
func (x *ListRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_file_proto_msgTypes[3]
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 ListRequest.ProtoReflect.Descriptor instead.
func (*ListRequest) Descriptor() ([]byte, []int) {
return file_proto_file_proto_rawDescGZIP(), []int{3}
}
func (x *ListRequest) GetProject() string {
if x != nil {
return x.Project
}
return ""
}
func (x *ListRequest) GetPath() string {
if x != nil {
return x.Path
}
return ""
}
type ListResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Files []*Record `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"`
}
func (x *ListResponse) Reset() {
*x = ListResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_file_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListResponse) ProtoMessage() {}
func (x *ListResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_file_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 ListResponse.ProtoReflect.Descriptor instead.
func (*ListResponse) Descriptor() ([]byte, []int) {
return file_proto_file_proto_rawDescGZIP(), []int{4}
}
func (x *ListResponse) GetFiles() []*Record {
if x != nil {
return x.Files
}
return nil
}
var File_proto_file_proto protoreflect.FileDescriptor
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,
0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x73, 0x5f, 0x64, 0x69, 0x72, 0x65,
0x63, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 0x73, 0x44,
0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x69, 0x6c, 0x65,
0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0c, 0x66, 0x69, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x18, 0x0a,
0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07,
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, 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_file_proto_rawDescOnce sync.Once
file_proto_file_proto_rawDescData = file_proto_file_proto_rawDesc
)
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_file_proto_rawDescData
}
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_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
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
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_file_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Record); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_file_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SaveRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_file_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SaveResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_file_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_file_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_file_proto_rawDesc,
NumEnums: 0,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_file_proto_goTypes,
DependencyIndexes: file_proto_file_proto_depIdxs,
MessageInfos: file_proto_file_proto_msgTypes,
}.Build()
File_proto_file_proto = out.File
file_proto_file_proto_rawDesc = nil
file_proto_file_proto_goTypes = nil
file_proto_file_proto_depIdxs = nil
}

110
file/proto/file.pb.micro.go Normal file
View File

@@ -0,0 +1,110 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/file.proto
package file
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
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.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for File service
func NewFileEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for File service
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 fileService struct {
c client.Client
name string
}
func NewFileService(name string, c client.Client) FileService {
return &fileService{
c: c,
name: name,
}
}
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 {
return nil, err
}
return out, nil
}
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 {
return nil, err
}
return out, nil
}
// Server API for File service
type FileHandler interface {
Save(context.Context, *SaveRequest, *SaveResponse) error
List(context.Context, *ListRequest, *ListResponse) error
}
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 File struct {
file
}
h := &fileHandler{hdlr}
return s.Handle(s.NewHandler(&File{h}, opts...))
}
type fileHandler struct {
FileHandler
}
func (h *fileHandler) Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error {
return h.FileHandler.Save(ctx, in, out)
}
func (h *fileHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error {
return h.FileHandler.List(ctx, in, out)
}

51
file/proto/file.proto Normal file
View File

@@ -0,0 +1,51 @@
syntax = "proto3";
package file;
option go_package = "./proto;file";
service File {
rpc Save(SaveRequest) returns (SaveResponse) {}
rpc List(ListRequest) returns (ListResponse) {}
}
message Record {
string id = 1;
// A custom string for namespacing purposes
// eg. file-of-mywebsite.com
string project = 2;
// Name of folder or file.
string name = 3;
// Path. Default is '/', ie. top level
string path = 4;
bool is_directory = 5;
// File contents. Empty for directories.
string file_contents = 6;
int64 created = 7;
int64 updated = 8;
// owner
string owner = 9;
}
// The save endpoint lets you batch save text file.
message SaveRequest {
repeated Record files = 1;
}
message SaveResponse {
}
// 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
// files inside that folder
// eg. '/docs'
string path = 2;
}
message ListResponse {
repeated Record files = 1;
}