files

package
v0.0.0-...-eec4b17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageTypeIPFS = "IPFS"

	EnvFileStorageBaseFolder   = "FILE_STORAGE_BASE_FOLDER"
	EnvFileStorageType         = "FILE_STORAGE_TYPE"
	EnvFileStorageIPFSEndpoint = "FILE_STORAGE_IPFS_ENDPOINT"
)

Variables

View Source
var (
	ErrInvalidLengthService        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowService          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupService = fmt.Errorf("proto: unexpected end of group")
)

Functions

func RegisterFilesServiceServer

func RegisterFilesServiceServer(s grpc1.Server, srv FilesServiceServer)

Types

type FileChunk

type FileChunk struct {
	FileName string `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"`
	Data     []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}

func (*FileChunk) Descriptor

func (*FileChunk) Descriptor() ([]byte, []int)

func (*FileChunk) GetData

func (m *FileChunk) GetData() []byte

func (*FileChunk) GetFileName

func (m *FileChunk) GetFileName() string

func (*FileChunk) Marshal

func (m *FileChunk) Marshal() (dAtA []byte, err error)

func (*FileChunk) MarshalTo

func (m *FileChunk) MarshalTo(dAtA []byte) (int, error)

func (*FileChunk) MarshalToSizedBuffer

func (m *FileChunk) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*FileChunk) ProtoMessage

func (*FileChunk) ProtoMessage()

func (*FileChunk) Reset

func (m *FileChunk) Reset()

func (*FileChunk) Size

func (m *FileChunk) Size() (n int)

func (*FileChunk) String

func (m *FileChunk) String() string

func (*FileChunk) Unmarshal

func (m *FileChunk) Unmarshal(dAtA []byte) error

func (*FileChunk) XXX_DiscardUnknown

func (m *FileChunk) XXX_DiscardUnknown()

func (*FileChunk) XXX_Marshal

func (m *FileChunk) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*FileChunk) XXX_Merge

func (m *FileChunk) XXX_Merge(src proto.Message)

func (*FileChunk) XXX_Size

func (m *FileChunk) XXX_Size() int

func (*FileChunk) XXX_Unmarshal

func (m *FileChunk) XXX_Unmarshal(b []byte) error

type FilesServiceClient

type FilesServiceClient interface {
	// UploadFile allows to upload a file
	UploadFile(ctx context.Context, opts ...grpc.CallOption) (FilesService_UploadFileClient, error)
	// GetFile allows to get the contents of a file
	GetFile(ctx context.Context, in *GetFileRequest, opts ...grpc.CallOption) (FilesService_GetFileClient, error)
}

FilesServiceClient is the client API for FilesService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewFilesServiceClient

func NewFilesServiceClient(cc grpc1.ClientConn) FilesServiceClient

type FilesServiceServer

type FilesServiceServer interface {
	// UploadFile allows to upload a file
	UploadFile(FilesService_UploadFileServer) error
	// GetFile allows to get the contents of a file
	GetFile(*GetFileRequest, FilesService_GetFileServer) error
}

FilesServiceServer is the server API for FilesService service.

type FilesService_GetFileClient

type FilesService_GetFileClient interface {
	Recv() (*FileChunk, error)
	grpc.ClientStream
}

type FilesService_GetFileServer

type FilesService_GetFileServer interface {
	Send(*FileChunk) error
	grpc.ServerStream
}

type FilesService_UploadFileClient

type FilesService_UploadFileClient interface {
	Send(*FileChunk) error
	CloseAndRecv() (*UploadFileResponse, error)
	grpc.ClientStream
}

type FilesService_UploadFileServer

type FilesService_UploadFileServer interface {
	SendAndClose(*UploadFileResponse) error
	Recv() (*FileChunk, error)
	grpc.ServerStream
}

type GetFileRequest

type GetFileRequest struct {
	FileName string `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"`
}

func (*GetFileRequest) Descriptor

func (*GetFileRequest) Descriptor() ([]byte, []int)

func (*GetFileRequest) GetFileName

func (m *GetFileRequest) GetFileName() string

func (*GetFileRequest) Marshal

func (m *GetFileRequest) Marshal() (dAtA []byte, err error)

func (*GetFileRequest) MarshalTo

func (m *GetFileRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetFileRequest) MarshalToSizedBuffer

func (m *GetFileRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetFileRequest) ProtoMessage

func (*GetFileRequest) ProtoMessage()

func (*GetFileRequest) Reset

func (m *GetFileRequest) Reset()

func (*GetFileRequest) Size

func (m *GetFileRequest) Size() (n int)

func (*GetFileRequest) String

func (m *GetFileRequest) String() string

func (*GetFileRequest) Unmarshal

func (m *GetFileRequest) Unmarshal(dAtA []byte) error

func (*GetFileRequest) XXX_DiscardUnknown

func (m *GetFileRequest) XXX_DiscardUnknown()

func (*GetFileRequest) XXX_Marshal

func (m *GetFileRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetFileRequest) XXX_Merge

func (m *GetFileRequest) XXX_Merge(src proto.Message)

func (*GetFileRequest) XXX_Size

func (m *GetFileRequest) XXX_Size() int

func (*GetFileRequest) XXX_Unmarshal

func (m *GetFileRequest) XXX_Unmarshal(b []byte) error

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(filesBasePath string, storage Storage) *Handler

NewHandler returns a new Handler instance

func NewHandlerFromEnvVariables

func NewHandlerFromEnvVariables() *Handler

NewHandlerFromEnvVariables builds a new Handler instance reading the configurations from the environment variables

func (*Handler) GetFile

func (h *Handler) GetFile(fileName string) (string, error)

GetFile gets the contents of the file having the given name, and writes them on a temporary file located at the returned path. Note: The caller should make sure the temporary file is deleted.

func (*Handler) SaveFile

func (h *Handler) SaveFile(fileName string, data []byte) (string, error)

SaveFile reads the given request and stores the associated file bytes into a new file within the upload folder.

func (*Handler) UploadFile

func (h *Handler) UploadFile(filePath string) (*UploadFileResponse, error)

UploadFile writes the contents of the file located at the given path in a temporary file, and uploads them remotely. After the uploads is completed, the path to the temporary file is returned along with the upload response. Note: The caller should make sure the temporary file is deleted.

type IPFSStorage

type IPFSStorage struct {
	// contains filtered or unexported fields
}

func NewIPFSStorage

func NewIPFSStorage(ipfsEndpoint string) *IPFSStorage

func NewIPFStorageFromEnvVariables

func NewIPFStorageFromEnvVariables() *IPFSStorage

func (*IPFSStorage) GetFile

func (s *IPFSStorage) GetFile(fileName string) ([]byte, error)

func (*IPFSStorage) UploadFile

func (s *IPFSStorage) UploadFile(filePath string) (string, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(handler *Handler) *Server

func NewServerFromEnvVariables

func NewServerFromEnvVariables() *Server

func (*Server) GetFile

func (s *Server) GetFile(request *GetFileRequest, stream FilesService_GetFileServer) error

GetFile implements FilesServiceServer

func (*Server) UploadFile

func (s *Server) UploadFile(stream FilesService_UploadFileServer) error

UploadFile implements FilesServiceServer

type Storage

type Storage interface {
	// UploadFile uploads a file to the storage and returns the uploaded file name
	// that can be used to retrieve the file later on using the GetFile method.
	UploadFile(filePath string) (string, error)

	// GetFile returns the file associated with the given name
	GetFile(fileName string) ([]byte, error)
}

func StorageFromEnvVariables

func StorageFromEnvVariables() Storage

type UnimplementedFilesServiceServer

type UnimplementedFilesServiceServer struct {
}

UnimplementedFilesServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedFilesServiceServer) GetFile

func (*UnimplementedFilesServiceServer) UploadFile

type UploadFileResponse

type UploadFileResponse struct {
	FileName string `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"`
}

func NewUploadFileResponse

func NewUploadFileResponse(fileName string) *UploadFileResponse

NewUploadFileResponse returns a new UploadFileResponse instance

func (*UploadFileResponse) Descriptor

func (*UploadFileResponse) Descriptor() ([]byte, []int)

func (*UploadFileResponse) GetFileName

func (m *UploadFileResponse) GetFileName() string

func (*UploadFileResponse) Marshal

func (m *UploadFileResponse) Marshal() (dAtA []byte, err error)

func (*UploadFileResponse) MarshalTo

func (m *UploadFileResponse) MarshalTo(dAtA []byte) (int, error)

func (*UploadFileResponse) MarshalToSizedBuffer

func (m *UploadFileResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*UploadFileResponse) ProtoMessage

func (*UploadFileResponse) ProtoMessage()

func (*UploadFileResponse) Reset

func (m *UploadFileResponse) Reset()

func (*UploadFileResponse) Size

func (m *UploadFileResponse) Size() (n int)

func (*UploadFileResponse) String

func (m *UploadFileResponse) String() string

func (*UploadFileResponse) Unmarshal

func (m *UploadFileResponse) Unmarshal(dAtA []byte) error

func (*UploadFileResponse) XXX_DiscardUnknown

func (m *UploadFileResponse) XXX_DiscardUnknown()

func (*UploadFileResponse) XXX_Marshal

func (m *UploadFileResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UploadFileResponse) XXX_Merge

func (m *UploadFileResponse) XXX_Merge(src proto.Message)

func (*UploadFileResponse) XXX_Size

func (m *UploadFileResponse) XXX_Size() int

func (*UploadFileResponse) XXX_Unmarshal

func (m *UploadFileResponse) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL