wsupload

package
v0.0.0-...-74e38f5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMessageType = errors.New("invalid message type")
	ErrInitUpload         = errors.New("could not initialize upload")
	ErrResumeUpload       = errors.New("could not resume upload")
)
View Source
var (
	ErrClosedByClient = errors.New("closed by client")
)
View Source
var OkMessage = Message{
	Type: MsgTypeOk,
}

Functions

This section is empty.

Types

type DataError

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

func (DataError) Error

func (e DataError) Error() string

type DataServiceInterface

type DataServiceInterface interface {
	NewUpload(identifier string, contentLength int, r io.Reader) error
	ResumeUpload(identifier string, r io.Reader) error
	GetUploadedBytes(identifier string) (int, error)
}

DataServiceInterface is an interface the websocket handler is prepared to receive.

type ErrorMessage

type ErrorMessage struct {
	Message
	Error string
}

func NewErrorMessage

func NewErrorMessage(err error) ErrorMessage

type Handler

type Handler struct {
	W       http.ResponseWriter
	R       *http.Request
	FS      DataServiceInterface
	Timeout time.Duration
	ErrCH   chan error

	// Delay between reading of successive messages.
	// This gives time for the server to handle messages
	// that are already in the system. This will typically be
	// something like 10ms.
	MessageDelay time.Duration
	// contains filtered or unexported fields
}

Websocket handler.

func (*Handler) Close

func (h *Handler) Close(status websocket.StatusCode, reason string) error

func (*Handler) Handle

func (h *Handler) Handle() error

Handle will implement the upload protocol. If an uploadId is provided it will assume that the upload is a continuing upload. Otherwise, it is a new upload.

Calling functions should assume that errors are already handled and that the connection will be closed on error. HOWEVER, in the case of success, the connection will *not* be closed. This way, the calling function can continue to send messages through this same connection.

Input error channel is to handle errors from the file service. The calling function can continue to send messages

func (*Handler) Send

func (h *Handler) Send(msg interface{}) error

type Message

type Message struct {
	Type MsgType
}

type MsgType

type MsgType string
var (
	MsgTypeInit   MsgType = "INIT"
	MsgTypeResume MsgType = "RESUME"
	MsgTypeStatus MsgType = "STATUS"
	MsgTypeOk     MsgType = "OK"
	MsgTypeError  MsgType = "ERROR"
)

type StartMessage

type StartMessage struct {
	Message
	Identifier    string
	ContentLength int
}

type StatusMessage

type StatusMessage struct {
	Message
	Uploaded int
}

func NewStatusMessage

func NewStatusMessage(uploaded int) StatusMessage

Jump to

Keyboard shortcuts

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