Documentation ¶
Index ¶
- Constants
- type ErrResponseHandler
- type File
- type Files
- type Gulter
- type NameGeneratorFunc
- type Option
- func WithErrorResponseHandler(errHandler ErrResponseHandler) Option
- func WithIgnoreNonExistentKey(ignore bool) Option
- func WithMaxFileSize(i int64) Option
- func WithNameFuncGenerator(nameFunc NameGeneratorFunc) Option
- func WithStorage(store Storage) Option
- func WithValidationFunc(validationFunc ValidationFunc) Option
- type Storage
- type UploadFileOptions
- type UploadedFileMetadata
- type ValidationFunc
Constants ¶
const (
ErrNoFilesUploaded = errorMsg("gulter: no uploadable files found in request")
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrResponseHandler ¶
type ErrResponseHandler func(error) http.HandlerFunc
ErrResponseHandler is a custom error that should be used to handle errors when an upload fails
type File ¶
type File struct { // FieldName denotes the field from the multipart form FieldName string `json:"field_name,omitempty"` // The name of the file from the client side OriginalName string `json:"original_name,omitempty"` // UploadedFileName denotes the name of the file when it was ultimately // uploaded to the storage layer. The distinction is important because of // potential changes to the file name that may be done UploadedFileName string `json:"uploaded_file_name,omitempty"` // FolderDestination is the folder that holds the uploaded file FolderDestination string `json:"folder_destination,omitempty"` // StorageKey can be used to retrieve the file from the storage backend StorageKey string `json:"storage_key,omitempty"` // MimeType of the uploaded file MimeType string `json:"mime_type,omitempty"` // Size in bytes of the uploaded file Size int64 `json:"size,omitempty"` }
type NameGeneratorFunc ¶
NameGeneratorFunc allows you alter the name of the file before it is ultimately uplaoded and stored. This is necessarily if you have to adhere to specific formats as an example
type Option ¶
type Option func(*Gulter)
func WithErrorResponseHandler ¶
func WithErrorResponseHandler(errHandler ErrResponseHandler) Option
func WithMaxFileSize ¶
WithMaxFileSize allows you limit the size of file uploads to accept
func WithNameFuncGenerator ¶
func WithNameFuncGenerator(nameFunc NameGeneratorFunc) Option
WithNameFuncGenerator allows you configure how you'd like to rename your uploaded files
func WithStorage ¶
func WithValidationFunc ¶
func WithValidationFunc(validationFunc ValidationFunc) Option
type Storage ¶
type Storage interface { // Upload copies the reader to the backend file storage // The name of the file is also provided. Upload(context.Context, io.Reader, *UploadFileOptions) (*UploadedFileMetadata, error) io.Closer }
type UploadFileOptions ¶
type UploadedFileMetadata ¶
type ValidationFunc ¶
ValidationFunc is a type that can be used to dynamically validate a file
func ChainValidators ¶
func ChainValidators(validators ...ValidationFunc) ValidationFunc
ChainValidators returns a validator that accepts multiple validating criteriacriteria
func MimeTypeValidator ¶
func MimeTypeValidator(validMimeTypes ...string) ValidationFunc
MimeTypeValidator makes sure we only accept a valid mimetype. It takes in an array of supported mimes