assets

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package assets assists serving embedded assets via HTTP

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BLAKE3Sum

func BLAKE3Sum(data []byte) string

BLAKE3Sum calculates a BLAKE3-256 check from the given content and returns its base64 representation.

func BLAKE3SumFile

func BLAKE3SumFile(file io.Reader) (string, error)

BLAKE3SumFile calculates a BLAKE3-256 checksum for the file. If io.Seeker is implemented, the file will be rewind.

func ContentType

func ContentType(file fs.File) string

ContentType checks if the fs.File or its fs.FileInfo effectively provides the Content-Type, and returns it if so.

func ETags

func ETags(file fs.File) []string

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

func TypeByFilename(fileName string) string

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

type ContentTypeSetter interface {
	SetContentType(string) string
}

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

type ContentTypedFS interface {
	fs.FS

	ContentType(path string) (string, error)
}

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 ETagedFS

type ETagedFS interface {
	fs.FS

	ETags(path string) ([]string, error)
}

ETagedFS is the interface implemented by a file system

type ETagsSetter

type ETagsSetter interface {
	SetETags(...string) []string
}

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

type ETagsSetterFS interface {
	fs.FS

	SetETags(string, ...string) ([]string, error)
}

ETagsSetterFS is the interface implemented by a file system to set a file's ETags

type File

type File interface {
	fs.File
	io.ReadSeekCloser
}

File represents seek-able fs.File

Jump to

Keyboard shortcuts

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