fileupload

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package fileupload implements the functions, types, and interfaces for the module.

Package fileupload implements the functions, types, and interfaces for the module.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoFile                  = errors.String("no file provided")
	ErrInvalidRequest          = errors.String("invalid request")
	ErrUploadFailed            = errors.String("upload failed")
	ErrInvalidFile             = errors.String("invalid file")
	ErrInvalidReceiverResponse = errors.String("invalid receiver response")
)

Functions

func GRPC2Header

func GRPC2Header(header *fileuploadv1.FileHeader) fileupload.FileHeader

func GenerateFileHash

func GenerateFileHash(filename string) string

func GenerateHash

func GenerateHash(data string) string

func GenerateRandomHash

func GenerateRandomHash() string

func Header2GRPCHeader

func Header2GRPCHeader(header fileupload.FileHeader) *fileuploadv1.FileHeader

func NewBridgeUploader

func NewBridgeUploader(builder *Builder, service fileupload.Uploader) fileupload.BridgeUploader

NewBridgeUploader 创建一个新的桥接上传器

func NewGRPCReceiver

func NewGRPCReceiver(stream grpc.ServerStream) fileupload.Receiver

func NewGRPCUploader

func NewGRPCUploader(ctx context.Context, service *configv1.Service) (fileupload.Uploader, error)

func NewHTTPUploader

func NewHTTPUploader(ctx context.Context, service *configv1.Service) (fileupload.Uploader, error)

func ParseHeader

func ParseHeader(header fileupload.FileHeader) fileupload.FileInfo

func ParseMultipart

func ParseMultipart(header *multipart.FileHeader) fileupload.FileInfo

Types

type BridgeUploader

type BridgeUploader struct {
	Builder *Builder
	Service fileupload.Uploader
}

BridgeUploader 实现了HTTP到gRPC的桥接上传

func (*BridgeUploader) ServeHTTP

func (b *BridgeUploader) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 处理HTTP上传请求并转发到gRPC服务

type Builder

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

func NewBuilder

func NewBuilder(ss ...BuilderSetting) *Builder

NewBuilder creates a new httpBuilder with the given options

func (*Builder) Free

func (b *Builder) Free(buf []byte)

func (*Builder) Init

func (b *Builder) Init(ss ...BuilderSetting) *Builder

func (*Builder) NewBuffer

func (b *Builder) NewBuffer() []byte

func (*Builder) NewReceiver

func (b *Builder) NewReceiver(r *http.Request, w http.ResponseWriter) fileupload.Receiver

func (*Builder) NewUploader

func (b *Builder) NewUploader(ctx context.Context) fileupload.Uploader

func (*Builder) Timeout

func (b *Builder) Timeout() time.Duration

type BuilderSetting

type BuilderSetting = func(builder *Builder)

func WithBufferSize

func WithBufferSize(size int) BuilderSetting

func WithHash

func WithHash(hash func(name string) string) BuilderSetting

func WithServiceType

func WithServiceType(st fileupload.ServiceType) BuilderSetting

func WithTimeout

func WithTimeout(timeout time.Duration) BuilderSetting

func WithURI

func WithURI(uri string) BuilderSetting

type FolderUploader

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

func NewFolderUploader

func NewFolderUploader(builder Builder, basePath string) *FolderUploader

func (*FolderUploader) UploadFolder

func (f *FolderUploader) UploadFolder(ctx context.Context, path string) error

type HTTPReceiver

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

func (*HTTPReceiver) Finalize

func (r *HTTPReceiver) Finalize(ctx context.Context, resp fileupload.UploadResponse) error

Finalize write the finalize status to the client and close the upload process.

func (*HTTPReceiver) GetFileHeader

func (r *HTTPReceiver) GetFileHeader(ctx context.Context) (fileupload.FileHeader, error)

GetFileHeader read the file fileHeader from the request.

func (*HTTPReceiver) GetOffset

func (r *HTTPReceiver) GetOffset(ctx context.Context) (int64, error)

func (*HTTPReceiver) ReceiveFile

func (r *HTTPReceiver) ReceiveFile(ctx context.Context) (io.ReadCloser, error)

ReceiveFile read the file data to the server with path.

Jump to

Keyboard shortcuts

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