upload

package module
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Go uploader package

Run server

Default listen port is 9090

go run server/main.go

Run client

Upload file

go run client/cmd/main.go -P 9090 -s http -f ~/Downloads/sequel-pro-1.1.2.dmg 

Download file

Support Range Request


curl -v  http://localhost:9090/file/1694518204508062sequel-pro-1.1.2.dmg --output /dev/null
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1:9090...
* Connected to localhost (127.0.0.1) port 9090 (#0)
> GET /file/1694518204508062sequel-pro-1.1.2.dmg HTTP/1.1
> Host: localhost:9090
> User-Agent: curl/7.87.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Disposition: attachment; filename=
< Content-Length: 10628282
< Content-Type: application/octet-stream
< Last-Modified: Tue, 12 Sep 2023 11:30:04 GMT
< Date: Tue, 12 Sep 2023 11:31:10 GMT
<
{ [20194 bytes data]
100 10.1M  100 10.1M    0     0   435M      0 --:--:-- --:--:-- --:--:--  563M
* Connection #0 to host localhost left intact

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Dir = "upload"

Functions

func InitDir added in v1.1.8

func InitDir()

Types

type Chunk

type Chunk struct {
	ID        string
	Hash      string
	CreatedAt time.Time
}

type CreateUploadResponse

type CreateUploadResponse struct {
	UploadId string
}

type DownloadRequest

type DownloadRequest struct {
	UploadId string
	Req      *http.Request
}

type File

type File struct {
	UploadId string
	Filename string
	Size     uint64
}

type FileChunk

type FileChunk struct {
	Hash        string
	ChunkNumber int
}

type FileController

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

func NewFileController added in v1.2.2

func NewFileController(d dependency) FileController

func (*FileController) Download

func (c *FileController) Download(ctx *gin.Context)

func (*FileController) NewUpload

func (c *FileController) NewUpload(ctx *gin.Context)

func (*FileController) Reassemble

func (c *FileController) Reassemble(ctx *gin.Context)

func (*FileController) UploadChunk

func (c *FileController) UploadChunk(ctx *gin.Context)

type ReassembleChunksRequest

type ReassembleChunksRequest struct {
	UploadId string
	Chunks   []FileChunk
	Filename string
}

type ReassembleChunksResponse

type ReassembleChunksResponse struct {
	Hash     string
	Filename string
}

type Service added in v1.1.8

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

func NewService added in v1.2.2

func NewService(dep dependency) Service

func (Service) CreateUpload added in v1.1.8

func (u Service) CreateUpload() CreateUploadResponse

func (Service) Download added in v1.1.8

func (u Service) Download(req DownloadRequest, header http.Header, writer http.ResponseWriter) error

func (Service) ReassembleChunk added in v1.1.8

ReassembleChunk put chunks together

func (Service) UploadChunk added in v1.1.8

func (u Service) UploadChunk(req *http.Request) (*UploadChunkResponse, error)

UploadChunk upload each 4MB chunk of a file

type UploadChunkResponse

type UploadChunkResponse struct {
	ID   string
	Hash string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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