Documentation
¶
Index ¶
- func ServeStaticDir(urlPath, dirPath string, opts ...StaticServFileOption) (core.Handler, core.Handler)
- func ServeStaticFile(urlPath, filePath string, opts ...StaticServFileOption) core.Handler
- type DirData
- type DirTemplateData
- type FileData
- type StaticServFileOption
- func WithContentType(contentType string) StaticServFileOption
- func WithIndexFile(indexFile string) StaticServFileOption
- func WithPreCache() StaticServFileOption
- func WithPreCacheSize(size int64) StaticServFileOption
- func WithTitle(title string) StaticServFileOption
- func WithoutPreCache() StaticServFileOption
- func WithoutPreLoad() StaticServFileOption
- type StaticSevFileConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServeStaticDir ¶
func ServeStaticDir(urlPath, dirPath string, opts ...StaticServFileOption) (core.Handler, core.Handler)
ServeStaticDir serves a directory at the given URL path. If the directory contains a "index.html" file, it will be served as "/" route. If not a FileExplorer will be shown, by default. It is highly recommended to leave the PreLoad option enabled.
func ServeStaticFile ¶
func ServeStaticFile(urlPath, filePath string, opts ...StaticServFileOption) core.Handler
ServeStaticFile serves a static file.
Types ¶
type DirTemplateData ¶
type DirTemplateData struct {
Title string
BaseUrl string
IndexFileExists bool
Files []FileData
Dirs []DirData
}
DirTemplateData holds the data for the directory template
type StaticServFileOption ¶
type StaticServFileOption func(*StaticSevFileConfig)
StaticServFileOption is a function that configures a StaticSevFileConfig.
func WithContentType ¶
func WithContentType(contentType string) StaticServFileOption
WithContentType sets the content type of the file.
func WithIndexFile ¶
func WithIndexFile(indexFile string) StaticServFileOption
WithIndexFile sets the index file for the directory.
func WithPreCache ¶
func WithPreCache() StaticServFileOption
WithPreCache it will load files into memory on startup, even if bigger than the maxPreCacheSize. Caching will mainly reduce latency. With NVME drives, the speed difference is negligible.
func WithPreCacheSize ¶
func WithPreCacheSize(size int64) StaticServFileOption
WithPreCacheSize sets the maximum size of the pre-cache.
func WithTitle ¶
func WithTitle(title string) StaticServFileOption
WithTitle sets the title for the directory listing page.
func WithoutPreCache ¶
func WithoutPreCache() StaticServFileOption
WithoutPreCache it will not cache files on startup.
func WithoutPreLoad ¶
func WithoutPreLoad() StaticServFileOption
WithoutPreLoad it will not look if files exits on startup! Be careful if using this option with a Directory, this function will expose all files in the directory, even if created after Server start! This will also disable pre-caching.
type StaticSevFileConfig ¶
type StaticSevFileConfig struct {
Title string
// contains filtered or unexported fields
}
StaticSevFileConfig holds the configuration for serving a static file.
func NewStaticServeFileConfig ¶
func NewStaticServeFileConfig(opts ...StaticServFileOption) *StaticSevFileConfig
NewStaticServeFileConfig creates a new StaticSevFileConfig.