Documentation
¶
Overview ¶
Package assets assists serving embedded assets via HTTP
Index ¶
- func BLAKE3Sum(data []byte) string
- func BLAKE3SumFile(file io.Reader) (string, error)
- func ContentType(file fs.File) string
- func ETags(file fs.File) []string
- func ServeFile(rw http.ResponseWriter, req *http.Request, file File)
- func TypeByFilename(fileName string) string
- func TypeBySniffing(file io.ReadSeeker) (string, error)
- type ContentTypeSetter
- type ContentTypeSetterFS
- type ContentTyped
- type ContentTypedFS
- type ETaged
- type ETagedFS
- type ETagsSetter
- type ETagsSetterFS
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BLAKE3Sum ¶
BLAKE3Sum calculates a BLAKE3-256 check from the given content and returns its base64 representation.
func BLAKE3SumFile ¶
BLAKE3SumFile calculates a BLAKE3-256 checksum for the file. If io.Seeker is implemented, the file will be rewind.
func ContentType ¶
ContentType checks if the fs.File or its fs.FileInfo effectively provides the Content-Type, and returns it if so.
func ETags ¶
ETags checks the fs.File and fs.FileInfo to see if they implement the ETaged interface, and return their output.
func ServeFile ¶
func ServeFile(rw http.ResponseWriter, req *http.Request, file File)
ServeFile serves the contents of the given File.
func TypeByFilename ¶
TypeByFilename attempts to infer the ContentType from the filename. It will return "" if unknown.
func TypeBySniffing ¶
func TypeBySniffing(file io.ReadSeeker) (string, error)
TypeBySniffing looks at the first 512 bytes of data to attempt to determine ContentType.
Types ¶
type ContentTypeSetter ¶
ContentTypeSetter is the interface that allows a fs.File or its fs.FileInfo to assign a MIME Content-Type to it. if empty it will be ignored
type ContentTypeSetterFS ¶
type ContentTypeSetterFS interface { fs.FS SetContentType(path, contentType string) (string, error) }
ContentTypeSetterFS is the interface implemented by a file system to set a file's MIME Content-Type.
type ContentTyped ¶
type ContentTyped interface {
ContentType() string
}
ContentTyped allows files to declare their Content-Type.
type ContentTypedFS ¶
ContentTypedFS is the interface implemented by a file system to get a file's MIME Content-Type
type ETaged ¶
type ETaged interface {
ETags() []string
}
ETaged allows files to declare their ETag to enable proper caching.
type ETagsSetter ¶
ETagsSetter is the interface that allows a fs.File or its fs.FileInfo to assign a ETags to it. Previous values will be removed and returned. If none is provided, it will return the current values unmodified.
type ETagsSetterFS ¶
ETagsSetterFS is the interface implemented by a file system to set a file's ETags