mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
add save batch endpoint to file service
This commit is contained in:
@@ -75,6 +75,27 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
|
||||
|
||||
log.Info("Received File.Save request")
|
||||
|
||||
// prefix the tenant
|
||||
req.File.Id = tenantId + "/" + req.File.Id
|
||||
req.File.Project = tenantId + "/" + req.File.Project
|
||||
|
||||
// create the file
|
||||
err := e.db.Create(req.File)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *File) BatchSave(ctx context.Context, req *file.BatchSaveRequest, rsp *file.BatchSaveResponse) error {
|
||||
tenantId, ok := tenant.FromContext(ctx)
|
||||
if !ok {
|
||||
tenantId = "micro"
|
||||
}
|
||||
|
||||
log.Info("Received File.BatchSave request")
|
||||
|
||||
for _, reqFile := range req.Files {
|
||||
// prefix the tenant
|
||||
reqFile.Id = tenantId + "/" + reqFile.Id
|
||||
@@ -90,6 +111,7 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListResponse) error {
|
||||
log.Info("Received File.List request")
|
||||
|
||||
@@ -116,6 +138,10 @@ func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListRe
|
||||
file.Id = strings.TrimPrefix(file.Id, tenantId+"/")
|
||||
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
||||
|
||||
// strip the file contents
|
||||
// no file listing ever contains it
|
||||
file.Data = ""
|
||||
|
||||
// if requesting all files or path matches
|
||||
if req.Path == "" || strings.HasPrefix(file.Path, req.Path) {
|
||||
rsp.Files = append(rsp.Files, file)
|
||||
|
||||
@@ -150,6 +150,92 @@ func (x *Record) GetMetadata() map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Batch save multiple files in one call
|
||||
type BatchSaveRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Files []*Record `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"`
|
||||
}
|
||||
|
||||
func (x *BatchSaveRequest) Reset() {
|
||||
*x = BatchSaveRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BatchSaveRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BatchSaveRequest) ProtoMessage() {}
|
||||
|
||||
func (x *BatchSaveRequest) 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 BatchSaveRequest.ProtoReflect.Descriptor instead.
|
||||
func (*BatchSaveRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *BatchSaveRequest) GetFiles() []*Record {
|
||||
if x != nil {
|
||||
return x.Files
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BatchSaveResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *BatchSaveResponse) Reset() {
|
||||
*x = BatchSaveResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BatchSaveResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BatchSaveResponse) ProtoMessage() {}
|
||||
|
||||
func (x *BatchSaveResponse) 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 BatchSaveResponse.ProtoReflect.Descriptor instead.
|
||||
func (*BatchSaveResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
// Read a file by path
|
||||
type ReadRequest struct {
|
||||
state protoimpl.MessageState
|
||||
@@ -165,7 +251,7 @@ type ReadRequest struct {
|
||||
func (x *ReadRequest) Reset() {
|
||||
*x = ReadRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[1]
|
||||
mi := &file_proto_file_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -178,7 +264,7 @@ func (x *ReadRequest) String() string {
|
||||
func (*ReadRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ReadRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_file_proto_msgTypes[1]
|
||||
mi := &file_proto_file_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -191,7 +277,7 @@ func (x *ReadRequest) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use ReadRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ReadRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{1}
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *ReadRequest) GetProject() string {
|
||||
@@ -220,7 +306,7 @@ type ReadResponse struct {
|
||||
func (x *ReadResponse) Reset() {
|
||||
*x = ReadResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[2]
|
||||
mi := &file_proto_file_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -233,7 +319,7 @@ func (x *ReadResponse) String() string {
|
||||
func (*ReadResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ReadResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_file_proto_msgTypes[2]
|
||||
mi := &file_proto_file_proto_msgTypes[4]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -246,7 +332,7 @@ func (x *ReadResponse) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use ReadResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ReadResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{2}
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ReadResponse) GetFile() *Record {
|
||||
@@ -256,19 +342,19 @@ func (x *ReadResponse) GetFile() *Record {
|
||||
return nil
|
||||
}
|
||||
|
||||
// The save endpoint lets you batch save text file.
|
||||
// Save a 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"`
|
||||
File *Record `protobuf:"bytes,1,opt,name=file,proto3" json:"file,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SaveRequest) Reset() {
|
||||
*x = SaveRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[3]
|
||||
mi := &file_proto_file_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -281,7 +367,7 @@ func (x *SaveRequest) String() string {
|
||||
func (*SaveRequest) ProtoMessage() {}
|
||||
|
||||
func (x *SaveRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_file_proto_msgTypes[3]
|
||||
mi := &file_proto_file_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -294,12 +380,12 @@ func (x *SaveRequest) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use SaveRequest.ProtoReflect.Descriptor instead.
|
||||
func (*SaveRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{3}
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *SaveRequest) GetFiles() []*Record {
|
||||
func (x *SaveRequest) GetFile() *Record {
|
||||
if x != nil {
|
||||
return x.Files
|
||||
return x.File
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -313,7 +399,7 @@ type SaveResponse struct {
|
||||
func (x *SaveResponse) Reset() {
|
||||
*x = SaveResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[4]
|
||||
mi := &file_proto_file_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -326,7 +412,7 @@ func (x *SaveResponse) String() string {
|
||||
func (*SaveResponse) ProtoMessage() {}
|
||||
|
||||
func (x *SaveResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_file_proto_msgTypes[4]
|
||||
mi := &file_proto_file_proto_msgTypes[6]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -339,7 +425,7 @@ func (x *SaveResponse) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use SaveResponse.ProtoReflect.Descriptor instead.
|
||||
func (*SaveResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{4}
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
// List file by their project and optionally a path.
|
||||
@@ -360,7 +446,7 @@ type ListRequest struct {
|
||||
func (x *ListRequest) Reset() {
|
||||
*x = ListRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[5]
|
||||
mi := &file_proto_file_proto_msgTypes[7]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -373,7 +459,7 @@ func (x *ListRequest) String() string {
|
||||
func (*ListRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_file_proto_msgTypes[5]
|
||||
mi := &file_proto_file_proto_msgTypes[7]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -386,7 +472,7 @@ func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use ListRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ListRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{5}
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{7}
|
||||
}
|
||||
|
||||
func (x *ListRequest) GetProject() string {
|
||||
@@ -414,7 +500,7 @@ type ListResponse struct {
|
||||
func (x *ListResponse) Reset() {
|
||||
*x = ListResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_file_proto_msgTypes[6]
|
||||
mi := &file_proto_file_proto_msgTypes[8]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -427,7 +513,7 @@ func (x *ListResponse) String() string {
|
||||
func (*ListResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_file_proto_msgTypes[6]
|
||||
mi := &file_proto_file_proto_msgTypes[8]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -440,7 +526,7 @@ func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use ListResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{6}
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{8}
|
||||
}
|
||||
|
||||
func (x *ListResponse) GetFiles() []*Record {
|
||||
@@ -475,37 +561,45 @@ var file_proto_file_proto_rawDesc = []byte{
|
||||
0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
|
||||
0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65,
|
||||
0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x3b, 0x0a, 0x0b, 0x52,
|
||||
0x65, 0x61, 0x64, 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, 0x30, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65,
|
||||
0x63, 0x6f, 0x72, 0x64, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 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, 0x99,
|
||||
0x01, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12,
|
||||
0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x1a, 0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 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,
|
||||
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x36, 0x0a, 0x10, 0x42,
|
||||
0x61, 0x74, 0x63, 0x68, 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, 0x13, 0x0a, 0x11, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x61, 0x76, 0x65,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3b, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64,
|
||||
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, 0x30, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72,
|
||||
0x64, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x2f, 0x0a, 0x0b, 0x53, 0x61, 0x76, 0x65, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, 0x6f,
|
||||
0x72, 0x64, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 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, 0xd9, 0x01, 0x0a, 0x04, 0x46, 0x69,
|
||||
0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x11, 0x2e, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e,
|
||||
0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x61, 0x64, 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, 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, 0x3e, 0x0a, 0x09, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x61,
|
||||
0x76, 0x65, 0x12, 0x16, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53,
|
||||
0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x61, 0x76, 0x65, 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 (
|
||||
@@ -520,33 +614,38 @@ func file_proto_file_proto_rawDescGZIP() []byte {
|
||||
return file_proto_file_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_file_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
|
||||
var file_proto_file_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
||||
var file_proto_file_proto_goTypes = []interface{}{
|
||||
(*Record)(nil), // 0: file.Record
|
||||
(*ReadRequest)(nil), // 1: file.ReadRequest
|
||||
(*ReadResponse)(nil), // 2: file.ReadResponse
|
||||
(*SaveRequest)(nil), // 3: file.SaveRequest
|
||||
(*SaveResponse)(nil), // 4: file.SaveResponse
|
||||
(*ListRequest)(nil), // 5: file.ListRequest
|
||||
(*ListResponse)(nil), // 6: file.ListResponse
|
||||
nil, // 7: file.Record.MetadataEntry
|
||||
(*Record)(nil), // 0: file.Record
|
||||
(*BatchSaveRequest)(nil), // 1: file.BatchSaveRequest
|
||||
(*BatchSaveResponse)(nil), // 2: file.BatchSaveResponse
|
||||
(*ReadRequest)(nil), // 3: file.ReadRequest
|
||||
(*ReadResponse)(nil), // 4: file.ReadResponse
|
||||
(*SaveRequest)(nil), // 5: file.SaveRequest
|
||||
(*SaveResponse)(nil), // 6: file.SaveResponse
|
||||
(*ListRequest)(nil), // 7: file.ListRequest
|
||||
(*ListResponse)(nil), // 8: file.ListResponse
|
||||
nil, // 9: file.Record.MetadataEntry
|
||||
}
|
||||
var file_proto_file_proto_depIdxs = []int32{
|
||||
7, // 0: file.Record.metadata:type_name -> file.Record.MetadataEntry
|
||||
0, // 1: file.ReadResponse.file:type_name -> file.Record
|
||||
0, // 2: file.SaveRequest.files:type_name -> file.Record
|
||||
0, // 3: file.ListResponse.files:type_name -> file.Record
|
||||
1, // 4: file.File.Read:input_type -> file.ReadRequest
|
||||
3, // 5: file.File.Save:input_type -> file.SaveRequest
|
||||
5, // 6: file.File.List:input_type -> file.ListRequest
|
||||
2, // 7: file.File.Read:output_type -> file.ReadResponse
|
||||
4, // 8: file.File.Save:output_type -> file.SaveResponse
|
||||
6, // 9: file.File.List:output_type -> file.ListResponse
|
||||
7, // [7:10] is the sub-list for method output_type
|
||||
4, // [4:7] is the sub-list for method input_type
|
||||
4, // [4:4] is the sub-list for extension type_name
|
||||
4, // [4:4] is the sub-list for extension extendee
|
||||
0, // [0:4] is the sub-list for field type_name
|
||||
9, // 0: file.Record.metadata:type_name -> file.Record.MetadataEntry
|
||||
0, // 1: file.BatchSaveRequest.files:type_name -> file.Record
|
||||
0, // 2: file.ReadResponse.file:type_name -> file.Record
|
||||
0, // 3: file.SaveRequest.file:type_name -> file.Record
|
||||
0, // 4: file.ListResponse.files:type_name -> file.Record
|
||||
3, // 5: file.File.Read:input_type -> file.ReadRequest
|
||||
7, // 6: file.File.List:input_type -> file.ListRequest
|
||||
5, // 7: file.File.Save:input_type -> file.SaveRequest
|
||||
1, // 8: file.File.BatchSave:input_type -> file.BatchSaveRequest
|
||||
4, // 9: file.File.Read:output_type -> file.ReadResponse
|
||||
8, // 10: file.File.List:output_type -> file.ListResponse
|
||||
6, // 11: file.File.Save:output_type -> file.SaveResponse
|
||||
2, // 12: file.File.BatchSave:output_type -> file.BatchSaveResponse
|
||||
9, // [9:13] is the sub-list for method output_type
|
||||
5, // [5:9] is the sub-list for method input_type
|
||||
5, // [5:5] is the sub-list for extension type_name
|
||||
5, // [5:5] is the sub-list for extension extendee
|
||||
0, // [0:5] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_file_proto_init() }
|
||||
@@ -568,7 +667,7 @@ func file_proto_file_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_file_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ReadRequest); i {
|
||||
switch v := v.(*BatchSaveRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -580,7 +679,7 @@ func file_proto_file_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_file_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ReadResponse); i {
|
||||
switch v := v.(*BatchSaveResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -592,7 +691,7 @@ func file_proto_file_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_file_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SaveRequest); i {
|
||||
switch v := v.(*ReadRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -604,7 +703,7 @@ func file_proto_file_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_file_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SaveResponse); i {
|
||||
switch v := v.(*ReadResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -616,7 +715,7 @@ func file_proto_file_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_file_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListRequest); i {
|
||||
switch v := v.(*SaveRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -628,6 +727,30 @@ func file_proto_file_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_file_proto_msgTypes[6].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[7].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[8].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -646,7 +769,7 @@ func file_proto_file_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_file_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 8,
|
||||
NumMessages: 10,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -43,8 +43,9 @@ func NewFileEndpoints() []*api.Endpoint {
|
||||
|
||||
type FileService interface {
|
||||
Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error)
|
||||
Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error)
|
||||
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
|
||||
Save(ctx context.Context, in *SaveRequest, opts ...client.CallOption) (*SaveResponse, error)
|
||||
BatchSave(ctx context.Context, in *BatchSaveRequest, opts ...client.CallOption) (*BatchSaveResponse, error)
|
||||
}
|
||||
|
||||
type fileService struct {
|
||||
@@ -69,6 +70,16 @@ func (c *fileService) Read(ctx context.Context, in *ReadRequest, opts ...client.
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -79,9 +90,9 @@ func (c *fileService) Save(ctx context.Context, in *SaveRequest, opts ...client.
|
||||
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)
|
||||
func (c *fileService) BatchSave(ctx context.Context, in *BatchSaveRequest, opts ...client.CallOption) (*BatchSaveResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "File.BatchSave", in)
|
||||
out := new(BatchSaveResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -93,15 +104,17 @@ func (c *fileService) List(ctx context.Context, in *ListRequest, opts ...client.
|
||||
|
||||
type FileHandler interface {
|
||||
Read(context.Context, *ReadRequest, *ReadResponse) error
|
||||
Save(context.Context, *SaveRequest, *SaveResponse) error
|
||||
List(context.Context, *ListRequest, *ListResponse) error
|
||||
Save(context.Context, *SaveRequest, *SaveResponse) error
|
||||
BatchSave(context.Context, *BatchSaveRequest, *BatchSaveResponse) error
|
||||
}
|
||||
|
||||
func RegisterFileHandler(s server.Server, hdlr FileHandler, opts ...server.HandlerOption) error {
|
||||
type file interface {
|
||||
Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error
|
||||
Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error
|
||||
List(ctx context.Context, in *ListRequest, out *ListResponse) error
|
||||
Save(ctx context.Context, in *SaveRequest, out *SaveResponse) error
|
||||
BatchSave(ctx context.Context, in *BatchSaveRequest, out *BatchSaveResponse) error
|
||||
}
|
||||
type File struct {
|
||||
file
|
||||
@@ -118,10 +131,14 @@ func (h *fileHandler) Read(ctx context.Context, in *ReadRequest, out *ReadRespon
|
||||
return h.FileHandler.Read(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *fileHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error {
|
||||
return h.FileHandler.List(ctx, in, out)
|
||||
}
|
||||
|
||||
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)
|
||||
func (h *fileHandler) BatchSave(ctx context.Context, in *BatchSaveRequest, out *BatchSaveResponse) error {
|
||||
return h.FileHandler.BatchSave(ctx, in, out)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ option go_package = "./proto;file";
|
||||
|
||||
service File {
|
||||
rpc Read(ReadRequest) returns (ReadResponse) {}
|
||||
rpc Save(SaveRequest) returns (SaveResponse) {}
|
||||
rpc List(ListRequest) returns (ListResponse) {}
|
||||
rpc Save(SaveRequest) returns (SaveResponse) {}
|
||||
rpc BatchSave(BatchSaveRequest) returns (BatchSaveResponse) {}
|
||||
}
|
||||
|
||||
message Record {
|
||||
@@ -34,6 +35,14 @@ message Record {
|
||||
map<string,string> metadata = 10;
|
||||
}
|
||||
|
||||
// Batch save multiple files in one call
|
||||
message BatchSaveRequest {
|
||||
repeated Record files = 1;
|
||||
}
|
||||
|
||||
message BatchSaveResponse {
|
||||
}
|
||||
|
||||
// Read a file by path
|
||||
message ReadRequest {
|
||||
// project name
|
||||
@@ -47,9 +56,9 @@ message ReadResponse {
|
||||
Record file = 1;
|
||||
}
|
||||
|
||||
// The save endpoint lets you batch save text file.
|
||||
// Save a file
|
||||
message SaveRequest {
|
||||
repeated Record files = 1;
|
||||
Record file = 1;
|
||||
}
|
||||
|
||||
message SaveResponse {
|
||||
|
||||
Reference in New Issue
Block a user