upload

package
v0.0.0-...-c32710b Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidParameters tells the caller that incorrect, invalid parameters were supplied
	ErrInvalidParameters = errors.New("invalid parameters supplied")
	// ErrValidation tells the caller that the process cannot proceed because of validation errors
	ErrValidation = errors.New("validation error")
	// ErrService tells the caller that an application error happened
	ErrService = errors.New("application error occurred")
)

Functions

This section is empty.

Types

type EncryptionRequest

type EncryptionRequest struct {
	InitPassword string
	Password     string
	Token        string
}

EncryptionRequest contains parammeters used for encryption

type File

type File struct {
	File     io.Reader
	Name     string
	Size     int64
	MimeType string
	Enc      EncryptionRequest
}

File provides a reader for the payload and meta-data

type Handler

type Handler struct {
	handler.Handler
	Service Service
}

Handler defines the api logic for the upload-service

func (*Handler) DeleteItemByID

func (h *Handler) DeleteItemByID(user security.User, w http.ResponseWriter, r *http.Request) error

DeleteItemByID removes an upload item specified by it's id

func (*Handler) GetHandlers

func (h *Handler) GetHandlers() http.Handler

GetHandlers returns the upload handler routes

func (*Handler) GetItemByID

func (h *Handler) GetItemByID(user security.User, w http.ResponseWriter, r *http.Request) error

GetItemByID returns the uploaded item by it's id

func (*Handler) Upload

func (h *Handler) Upload(user security.User, w http.ResponseWriter, r *http.Request) error

Upload saves the provided payload using the store

type ItemResponse

type ItemResponse struct {
	*Upload
}

ItemResponse returns Result

func (ItemResponse) Render

Render the specific response

type Result

type Result struct {
	ID      string `json:"id"`
	Message string `json:"message"`
}

Result represents status of the upload opeation

type ResultResponse

type ResultResponse struct {
	*Result
	Status int `json:"-"` // ignore this
}

ResultResponse returns Result

func (ResultResponse) Render

Render the specific response

type Service

type Service interface {
	Save(file File) (string, error)
	Read(id string) (Upload, error)
	Delete(id string) error
}

Service contains the main logic of the upload package the Service takes care of saving, reading and deleting uploaded files

func NewService

func NewService(init ServiceOptions) Service

NewService creates a new Service instance

type ServiceOptions

type ServiceOptions struct {
	Logger           logging.Logger
	Store            Store
	MaxUploadSize    int64
	AllowedFileTypes []string
	// the Encryptionservice which is used to optionally encrypt the payload / change password of encrypted payload
	Crypter crypter.EncryptionService
	TimeOut string
}

ServiceOptions defines parameters used to initialize a new Service

type Store

type Store interface {
	Write(item Upload) (err error)
	Read(id string) (Upload, error)
	Delete(id string) (err error)
}

Store provides CRUD methods for uploads

func NewStore

func NewStore(path string) Store

NewStore create a new store instance

type Upload

type Upload struct {
	ID       string    `json:"id"`
	FileName string    `json:"fileName"`
	Payload  []byte    `json:"payload"`
	MimeType string    `json:"mimeType"`
	Created  time.Time `json:"created"`
}

Upload defines an entity within the persistence store

Jump to

Keyboard shortcuts

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