uploads

package
v0.0.0-...-c05fae0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFilePath

func GetFilePath(ctx context.Context) (string, bool)

GetFilePath returns the file path from the context. If the context does not contain a file path, the second return value will be false.

func GetUpload

func GetUpload(ctx context.Context) (model.Upload, bool)

GetUpload returns a model.Upload instance from the context. If the context does not contain an upload instance, the second return value will be false.

func MustGetFilePath

func MustGetFilePath(ctx context.Context) string

MustGetFilePath returns the file path from the context. In contrast to GetFilePath this function panics if the context does not contain a file path.

func MustGetUpload

func MustGetUpload(ctx context.Context) model.Upload

MustGetUpload returns a model.Upload instance from the context. In contrast to GetUpload this function panics if the context does not contain an upload instance.

func SetFilePath

func SetFilePath(ctx context.Context, path string) context.Context

SetFilePath sets the file path in ctx.

func SetUpload

func SetUpload(ctx context.Context, upload model.Upload) context.Context

SetUpload sets the song instance in ctx.

func UploadState

func UploadState(states ...model.UploadState) func(next http.Handler) http.Handler

UploadState is a middleware that checks if the upload is in one of the allowed states.

func ValidateFilePath

func ValidateFilePath(next http.Handler) http.Handler

ValidateFilePath is a middleware that validates the file path within an upload syntactically. If this middleware passes it is not guaranteed that the path actually exists. It is also not guaranteed that the path is allowed for a specific endpoint.

The root directory is normalized to ".".

Types

type Handler

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

Handler implements the /v1/uploads endpoints.

func NewHandler

func NewHandler(logger *slog.Logger, uploadRepo upload.Repository, uploadStore upload.Store) *Handler

NewHandler creates a new Handler instance using the specified service.

func (*Handler) Create

func (h *Handler) Create(w http.ResponseWriter, r *http.Request)

Create implements the POST /v1/uploads endpoint.

func (*Handler) Delete

func (h *Handler) Delete(w http.ResponseWriter, r *http.Request)

Delete implements the DELETE /v1/uploads/{uuid} endpoint.

func (*Handler) DeleteFile

func (h *Handler) DeleteFile(w http.ResponseWriter, r *http.Request)

DeleteFile implements the DELETE /v1/uploads/{uuid}/files/* endpoint.

func (*Handler) FetchUpload

func (h *Handler) FetchUpload(next http.Handler) http.Handler

FetchUpload is a middleware that fetches the model.Upload instance identified by the request and stores it in the request context.

func (*Handler) Find

func (h *Handler) Find(w http.ResponseWriter, r *http.Request)

Find implements the GET /v1/uploads endpoint.

func (*Handler) Get

func (h *Handler) Get(w http.ResponseWriter, r *http.Request)

Get implements the GET /v1/uploads/{uuid} endpoint.

func (*Handler) GetErrors

func (h *Handler) GetErrors(w http.ResponseWriter, r *http.Request)

GetErrors implements the GET /v1/uploads/{uuid}/errors endpoint.

func (*Handler) GetFile

func (h *Handler) GetFile(w http.ResponseWriter, r *http.Request)

GetFile implements the GET /v1/uploads/{uuid}/files/* endpoint.

func (*Handler) PutFile

func (h *Handler) PutFile(w http.ResponseWriter, r *http.Request)

PutFile implements the PUT /v1/uploads/{uuid}/files/* endpoint.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP processes HTTP requests for h.

Jump to

Keyboard shortcuts

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