Documentation ¶
Overview ¶
Package goup contains golang upload/download server and client.
Index ¶
- Constants
- Variables
- func Bearer(token string, handle http.HandlerFunc) http.HandlerFunc
- func BearerTokenGenerate() string
- func CreateChunkReader(fullPath string, partFrom, partTo uint64, limitRate uint64) (r io.ReadCloser, err error)
- func GetPartSize(totalSize, chunkSize, idx uint64) uint64
- func InitServer() error
- func NetHTTPUpload(w http.ResponseWriter, r *http.Request, rootDir string, limitSize uint64) error
- func NewRewindableMultiReader(readers ...io.Reader) io.Reader
- func ParseFormFile(m *multipart.Form) (*multipart.FileHeader, error)
- func Rewind(reader io.Reader) (err error)
- func SecureCompare(given string, actual string) bool
- func ServerHandle(code, cipher string, chunkSize, limitRate uint64, paths []string) http.HandlerFunc
- func TrimExt(filepath, ext string) string
- func Unwrap(a any) any
- func Wrap(reader io.Reader, closer io.Closer) io.ReadCloser
- func WriteJSON(w http.ResponseWriter, v interface{}) error
- type Adder
- type AdderFn
- type Client
- type Entry
- type Header
- type MultipartPayload
- type Opt
- type OptFn
- func WithBearer(v string) OptFn
- func WithChunkSize(v uint64) OptFn
- func WithCipher(v string) OptFn
- func WithCode(v string) OptFn
- func WithCoroutines(v int) OptFn
- func WithFullPath(v string) OptFn
- func WithHTTPClient(v *http.Client) OptFn
- func WithLimitRate(v uint64) OptFn
- func WithProgress(v Progress) OptFn
- func WithRename(v string) OptFn
- type PayloadFile
- type PayloadFileReader
- type PbReader
- type Progress
- type Range
- type Rewindable
- type RewindableFn
- type RewindableMultiReader
- type UnWrapper
- type UploadResult
Constants ¶
const ( // Authorization is the header name for Authorization Authorization = "Authorization" // ContentDisposition is header name for Content-Disposition ContentDisposition = "Content-Disposition" // ContentType is the header name for Content-Type ContentType = "Content-Type" // ContentLength is the header name for Content-Length ContentLength = "Content-Length" )
Variables ¶
var ErrMissingFile = errors.New("there is no uploaded file")
ErrMissingFile may be returned from FormFile when the is no uploaded file.
var RootDir = "./.goup"
RootDir settings. When finished uploading with success files are stored inside it.
Functions ¶
func Bearer ¶
func Bearer(token string, handle http.HandlerFunc) http.HandlerFunc
Bearer returns a Handler that authenticates via Bearer Auth. Writes a http.StatusUnauthorized if authentication fails.
func BearerTokenGenerate ¶
func BearerTokenGenerate() string
BearerTokenGenerate generates a random bearer token.
func CreateChunkReader ¶
func CreateChunkReader(fullPath string, partFrom, partTo uint64, limitRate uint64) (r io.ReadCloser, err error)
CreateChunkReader creates a chunk reader for the file.
func GetPartSize ¶
GetPartSize get the part size of idx-th chunk.
func NetHTTPUpload ¶
NetHTTPUpload upload
func NewRewindableMultiReader ¶
NewRewindableMultiReader returns a Reader that's the logical concatenation of the provided input readers. They're read sequentially. Once all inputs have returned EOF, Read will return EOF. If any of the readers return a non-nil, non-EOF error, Read will return that error.
func ParseFormFile ¶
func ParseFormFile(m *multipart.Form) (*multipart.FileHeader, error)
ParseFormFile returns the first file for the provided form key. FormFile calls ParseMultipartForm and ParseForm if necessary.
func SecureCompare ¶
SecureCompare performs a constant time compare of two strings to limit timing attacks.
func ServerHandle ¶
func ServerHandle(code, cipher string, chunkSize, limitRate uint64, paths []string) http.HandlerFunc
ServerHandle is main request/response handler for HTTP server.
func Wrap ¶
Wrap wraps reader and closer together to create an new io.ReadCloser.
The Read function will simply call the wrapped reader's Read function, while the Close function will call the wrapped closer's Close function.
If the wrapped reader is also an io.Closer, its Close function will be called in Close as well.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, v interface{}) error
WriteJSON writes the JSON of v to http.ResponseWriter.
Types ¶
type AdderFn ¶
type AdderFn func(value uint64)
AdderFn is a func prototype which implements Adder interface.
type Client ¶
type Client struct { *Opt ID string TotalSize uint64 LimitRate uint64 // contains filtered or unexported fields }
Client structure
type Header ¶
type Header struct { Session string Checksum string Curve string Salt string Range string Filename string }
Header is a header structure for the goup file transfer.
func ParseHeader ¶
ParseHeader parse the Content-Gulp Header to structure.
type MultipartPayload ¶
MultipartPayload is the multipart payload.
func PrepareMultipartPayload ¶
func PrepareMultipartPayload(fields map[string]interface{}) *MultipartPayload
PrepareMultipartPayload prepares the multipart playload of http request. Multipart request has the following structure:
POST /upload HTTP/1.1 Other-Headers: ... Content-Type: multipart/form-data; boundary=$boundary \r\n --$boundary\r\n 👈 request body starts here Content-Disposition: form-data; name="field1"\r\n Content-Type: text/plain; charset=utf-8\r\n Content-Length: 4\r\n \r\n $content\r\n --$boundary\r\n Content-Disposition: form-data; name="field2"\r\n ... --$boundary--\r\n
https://stackoverflow.com/questions/39761910/how-can-you-upload-files-as-a-stream-in-go/39781706 https://blog.depa.do/post/bufferless-multipart-post-in-go https://github.com/technoweenie/multipartstreamer
type Opt ¶
type Opt struct { ChunkSize uint64 LimitRate uint64 Progress *http.Client Rename string Bearer string FullPath string Code string Coroutines int Cipher string }
Opt is the client options.
type PayloadFile ¶
type PayloadFile struct { io.ReadCloser Name string Size int64 }
PayloadFile means the file payload.
type PayloadFileReader ¶
PayloadFileReader is the interface which means a reader which represents a file.
type Rewindable ¶
type Rewindable interface {
Rewind() error
}
Rewindable is an interface for anything that can be rewind like a file reader to seek start.
type RewindableFn ¶
type RewindableFn func() error
RewindableFn is a func which implements Rewindable.
type RewindableMultiReader ¶
type RewindableMultiReader struct {
// contains filtered or unexported fields
}
RewindableMultiReader implements a rewindable multi-reader.