Documentation ¶
Index ¶
- func FileExists(fs fs.StatFS, file string) bool
- func GetFileExtension(filename string) string
- func GetMIMEType(filesystem fs.FS, file string) (contentType string, size int64, err error)
- func IsDirectory(fs fs.StatFS, path string) bool
- type Embed
- type FS
- type File
- type MkdirFS
- type RemoveFS
- type WorkingDirFS
- type WritableFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExists ¶
FileExists returns true if the file at the given path exists and is readable. Returns false if the given file is a directory.
func GetFileExtension ¶
GetFileExtension returns the last part of a file name. If the file doesn't have an extension, returns an empty string.
func GetMIMEType ¶
GetMIMEType get the mime type and size of the given file. This function calls `http.DetectContentType`. If the detected content type could not be determined or if it's a text file, `GetMIMEType` will attempt to detect the MIME type based on the file extension. The following extensions are supported:
- `.jsonld`: "application/ld+json"
- `.json`: "application/json"
- `.js` / `.mjs`: "text/javascript"
- `.css`: "text/css"
If a specific MIME type cannot be determined, returns "application/octet-stream" as a fallback.
Types ¶
type Embed ¶
Embed is an extension of aimed at improving `embed.FS` by implementing `fs.StatFS` and a `Sub()` function.
func (Embed) Open ¶
Open opens the named file.
When Open returns an error, it should be of type *PathError with the Op field set to "open", the Path field set to name, and the Err field describing the problem.
Open should reject attempts to open names that do not satisfy ValidPath(name), returning a *PathError with Err set to ErrInvalid or ErrNotExist.
func (Embed) ReadDir ¶
ReadDir reads the named directory and returns a list of directory entries sorted by filename.
type FS ¶
An FS provides access to a hierarchical file system and implements `io/fs`'s `FS`, `ReadDirFS` and `StatFS` interfaces.
type File ¶
type File struct { Header *multipart.FileHeader MIMEType string }
File represents a file received from client.
func ParseMultipartFiles ¶
func ParseMultipartFiles(headers []*multipart.FileHeader) ([]File, error)
ParseMultipartFiles parse a single file field in a request.
type MkdirFS ¶
type MkdirFS interface { // MkdirAll creates a directory named path, // along with any necessary parents, and returns `nil`, // or else returns an error. // The permission bits perm (before umask) are used for all // directories that `MkdirAll` creates. // If path is already a directory, `MkdirAll` does nothing // and returns `nil`. MkdirAll(path string, perm fs.FileMode) error // Mkdir creates a new directory with the specified name and permission // bits (before umask). // If there is an error, it will be of type `*PathError`. Mkdir(path string, perm fs.FileMode) error }
A MkdirFS is a file system with a `Mkdir()` and a `MkdirAll()` methods.
type RemoveFS ¶
type RemoveFS interface { // Remove removes the named file or (empty) directory. // If there is an error, it will be of type `*PathError`. Remove(path string) error // RemoveAll removes path and any children it contains. // It removes everything it can but returns the first error // it encounters. If the path does not exist, `RemoveAll` // returns `nil` (no error). // If there is an error, it will be of type `*PathError`. RemoveAll(path string) error }
A RemoveFS is a file system with a `Remove()` and a `RemoveAll()` methods.
type WorkingDirFS ¶
type WorkingDirFS interface { // Getwd returns a rooted path name corresponding to the // current directory. If the current directory can be // reached via multiple paths (due to symbolic links), // Getwd may return any one of them. Getwd() (dir string, err error) }
A WorkingDirFS is a file system with a `Getwd()` method.
type WritableFS ¶
type WritableFS interface { // OpenFile is the generalized open call. It opens the named file with specified flag // (`O_RDONLY` etc.). If the file does not exist, and the `O_CREATE` flag // is passed, it is created with mode perm (before umask). If successful, // methods on the returned file can be used for I/O. // If there is an error, it will be of type `*PathError`. OpenFile(path string, flag int, perm fs.FileMode) (io.ReadWriteCloser, error) }
A WritableFS is a file system with a `OpenFile()` method.