static

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

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 DirData

type DirData struct {
	Name string
}

DirData holds the data for a directory

type DirTemplateData

type DirTemplateData struct {
	Title           string
	BaseUrl         string
	IndexFileExists bool
	Files           []FileData
	Dirs            []DirData
}

DirTemplateData holds the data for the directory template

type FileData

type FileData struct {
	DirPath string
	Name    string
	Size    int64
}

FileData holds the data for a file

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.

Jump to

Keyboard shortcuts

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