static

package module
v4.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 16 Imported by: 2

README

Documentation

Index

Constants

View Source
const (
	PluginName     = "static"
	RootPluginName = "http"
)

PluginName contains default service name.

Variables

This section is empty.

Functions

func SetEtag

func SetEtag(weak bool, f http.File, name string, w http.ResponseWriter)

SetEtag sets etag for the file

Types

type Config

type Config struct {
	// Dir contains name of directory to control access to.
	// Default - "."
	Dir string `mapstructure:"dir"`

	// CalculateEtag can be true/false and used to calculate etag for the static
	CalculateEtag bool `mapstructure:"calculate_etag"`

	// Weak etag `W/`
	Weak bool `mapstructure:"weak"`

	// forbid specifies list of file extensions which are forbidden for access.
	// example: .php, .exe, .bat, .htaccess and etc.
	Forbid []string `mapstructure:"forbid"`

	// Allow specifies list of file extensions which are allowed for access.
	// example: .php, .exe, .bat, .htaccess and etc.
	Allow []string `mapstructure:"allow"`

	// Request headers to add to every static.
	Request map[string]string `mapstructure:"request"`

	// Response headers to add to every static.
	Response map[string]string `mapstructure:"response"`
}

Config describes file location and controls access to them.

func (*Config) Valid

func (c *Config) Valid() error

Valid returns nil if config is valid.

type Configurer

type Configurer interface {
	// UnmarshalKey takes a single key and unmarshal it into a Struct.
	UnmarshalKey(name string, out any) error
	// Has checks if config section exists.
	Has(name string) bool
}

type Logger

type Logger interface {
	NamedLogger(name string) *zap.Logger
}

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin serves static files. Potentially convert into middleware?

func (*Plugin) Init

func (s *Plugin) Init(cfg Configurer, log Logger) error

Init must return configure service and return true if service hasStatus enabled. Must return error in case of misconfiguration. Services must not be used without proper configuration pushed first.

func (*Plugin) Middleware

func (s *Plugin) Middleware(next http.Handler) http.Handler

Middleware must return true if request/response pair is handled within the middleware.

func (*Plugin) Name

func (s *Plugin) Name() string

Jump to

Keyboard shortcuts

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