Documentation ¶
Overview ¶
Package server provides an HTTP server for serving static files.
Index ¶
- Constants
- func AddHeadersHandler(headers map[string]string, h http.Handler) http.Handler
- func AssetsHandler() http.Handler
- type BasicAuthHandler
- type DirEntryInfo
- type DirInfo
- type DirectoryListingTemplate
- type DirectoryListingTemplateConfig
- type File
- type FileHandler
- type FileSize
- type FileSystem
- type LoggingHandler
- type StaticServer
- type StaticServerConfig
Constants ¶
const AssetsPrefix = "/.h2static-assets/"
AssetsPrefix defines the URL prefix for static assets.
const CSSAsset = AssetsPrefix + "style.css"
CSSAsset defines the path of the CSS file.
const LogoAsset = AssetsPrefix + "logo.svg"
LogoAsset defines the path of the logo.
Variables ¶
This section is empty.
Functions ¶
func AddHeadersHandler ¶
AddHeadersHandler wraps an http.Handler adding headers.
func AssetsHandler ¶
AssetsHandler serves static assets for the server.
Types ¶
type BasicAuthHandler ¶
type BasicAuthHandler struct { http.Handler // User/password pairs Credentials map[string]string // The authentication realm Realm string }
BasicAuthHandler provides Basic Authorization.
func (BasicAuthHandler) ServeHTTP ¶
func (h BasicAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP logs server startup and serves via the configured handler.
type DirEntryInfo ¶
DirEntryInfo holds details for a directory entry.
type DirInfo ¶
type DirInfo struct { Name string IsRoot bool Entries []DirEntryInfo }
DirInfo holds details about the directory being listed.
type DirectoryListingTemplate ¶
type DirectoryListingTemplate struct { Config DirectoryListingTemplateConfig // contains filtered or unexported fields }
DirectoryListingTemplate is a template rendered for a directory.
func NewDirectoryListingTemplate ¶
func NewDirectoryListingTemplate(config DirectoryListingTemplateConfig) *DirectoryListingTemplate
NewDirectoryListingTemplate returns a DirectoryListingTemplate for the specified directory.
func (*DirectoryListingTemplate) RenderHTML ¶
func (t *DirectoryListingTemplate) RenderHTML(w http.ResponseWriter, path string, dir *File, sortColumn string, sortAsc bool) error
RenderHTML renders the HTML template for a directory.
func (*DirectoryListingTemplate) RenderJSON ¶
func (t *DirectoryListingTemplate) RenderJSON(w http.ResponseWriter, path string, dir *File, sortColumn string, sortAsc bool) error
RenderJSON returns JSON listing for a directory.
type DirectoryListingTemplateConfig ¶
type DirectoryListingTemplateConfig struct {
PathPrefix string
}
DirectoryListingTemplateConfig holds configuration for a DirectoryListingTemplate
type File ¶
File is an entry of a FileSystem entry.
If the entry is a directory and the filesystem is configured to hide dotfiles, the directory will also not list dotfiles under it.
type FileHandler ¶
type FileHandler struct { FileSystem FileSystem DirectoryIndex bool // contains filtered or unexported fields }
FileHandler is an http.Handler which serves static files under the specified filesystem.
func NewFileHandler ¶
func NewFileHandler(fileSystem FileSystem, directoryIndex bool, pathPrefix string) *FileHandler
NewFileHandler returns a FileHandler for the specified filesystem.
func (FileHandler) ServeHTTP ¶
func (f FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles a request for the static file serve.
type FileSystem ¶
FileSystem provides acess to files and directories under a certain root. It can optionally optionally:
- serve .htm(l) files for the corresponding path without suffix, if the original path is not found
- hide dotfiles
- allow access to file/directories outside the filesystem root via symlinks
type LoggingHandler ¶
LoggingHandler wraps an http.Handler providing logging at startup.
func (LoggingHandler) ServeHTTP ¶
func (h LoggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP logs server startup and serves via the configured handler.
type StaticServer ¶
type StaticServer struct {
Config StaticServerConfig
}
StaticServer is a static HTTP server.
func NewStaticServer ¶
func NewStaticServer(config StaticServerConfig) (*StaticServer, error)
NewStaticServer returns a StaticServer.
func (*StaticServer) Scheme ¶
func (s *StaticServer) Scheme() string
Scheme returns the server scheme (http or https)
type StaticServerConfig ¶
type StaticServerConfig struct { Addr string AllowOutsideSymlinks bool CSS string DebugAddr string Dir string DisableH2 bool DisableIndex bool DisableLookupWithSuffix bool Log bool PasswordFile string RequestPathPrefix string ShowDotFiles bool TLSCert string TLSKey string }
StaticServerConfig holds configuration options for a StaticServer.
func (StaticServerConfig) IsHTTPS ¶
func (c StaticServerConfig) IsHTTPS() bool
IsHTTPS returns whether HTTPS is enabled in the config.
func (StaticServerConfig) Port ¶
func (c StaticServerConfig) Port() uint16
Port returns the port from the config.
func (StaticServerConfig) Validate ¶
func (c StaticServerConfig) Validate() error
Validate raises an error if StaticServerConfig is invalid.