esfs

package module
v0.0.0-...-441456f Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 12 Imported by: 0

README

ESFS (Embeddable Server for File System)

Simple embedded (and not only) file server

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(addr string, options ...Option) error

func ServeDir

func ServeDir(addr, dir string, options ...Option) error

func ServeFS

func ServeFS(addr string, fileSystem fs.FS, options ...Option) error

Types

type Config

type Config struct {
	Addr             string           `validate:"hostname_port"`
	Server           *fasthttp.Server `validate:"required"`
	GracefulShutdown bool             `validate:"-"`
	SubDir           string           `validate:"-"`

	Dir string `validate:"omitempty,dir"`

	FileSystem     fs.FS       `validate:"required_without=Dir"`
	TempDir        string      `validate:"omitempty,required_with=FileSystem,dir"`
	TempDirPattern string      `validate:"-"`
	TempFilesPerm  os.FileMode `validate:"required_with=FileSystem"`

	IndexNames         []string                 `validate:"-"`
	GenerateIndexPages bool                     `validate:"-"`
	Compress           bool                     `validate:"-"`
	CompressBrotli     bool                     `validate:"omitempty,excluded_unless=Compress false"`
	AcceptByteRange    bool                     `validate:"-"`
	PathRewrite        fasthttp.PathRewriteFunc `validate:"-"`
	PathRewriteToRoot  bool                     `validate:"-"`
	PathNotFound       fasthttp.RequestHandler  `validate:"-"`
	CacheDuration      time.Duration            `validate:"gte=0"`
}

type DiscardLogger

type DiscardLogger struct{}

func (DiscardLogger) Printf

func (d DiscardLogger) Printf(format string, args ...any)

type Option

type Option func(cfg *Config) error

func WithAcceptByteRange

func WithAcceptByteRange() Option

func WithCacheDuration

func WithCacheDuration(duration time.Duration) Option

func WithCompress

func WithCompress() Option

func WithCompressBrotli

func WithCompressBrotli() Option

func WithDir

func WithDir(dir string) Option

func WithFS

func WithFS(fileSystem fs.FS) Option

func WithGenerateIndexPages

func WithGenerateIndexPages() Option

func WithGracefulShutdown

func WithGracefulShutdown() Option

func WithIndexNames

func WithIndexNames(names ...string) Option

func WithPathNotFound

func WithPathNotFound(handler fasthttp.RequestHandler) Option

func WithPathRewrite

func WithPathRewrite(rewrite fasthttp.PathRewriteFunc) Option

func WithPathRewriteToRoot

func WithPathRewriteToRoot() Option

func WithServer

func WithServer(server *fasthttp.Server) Option

func WithSubDir

func WithSubDir(dir string) Option

func WithTempDir

func WithTempDir(dir string) Option

func WithTempDirPattern

func WithTempDirPattern(pattern string) Option

func WithTempFilesPerm

func WithTempFilesPerm(perm os.FileMode) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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