Documentation
¶
Overview ¶
Package engine provides the server configuration struct and several functions for serving files over HTTP
Index ¶
- Constants
- Variables
- func AtShutdown(shutdownFunction func())
- func InsertScriptTag(htmldata, js []byte) []byte
- func ReadIgnoreFile(ignoreFilePath string) ([]string, error)
- func RecorderToString(recorder *httptest.ResponseRecorder) (string, error)
- func ShouldIgnore(filename string, patterns []string) bool
- func ValidGCSS(gcssdata []byte, errorReturn chan error)
- func WriteRecorder(w http.ResponseWriter, recorder *httptest.ResponseRecorder) (int64, error)
- type Config
- func (ac *Config) AmberPage(w http.ResponseWriter, req *http.Request, filename string, amberdata []byte, ...)
- func (ac *Config) ClearCache()
- func (ac *Config) ClientCanGzip(req *http.Request) bool
- func (ac *Config) Close()
- func (ac *Config) CombinedLogFormat(req *http.Request, statusCode int, byteSize int64) string
- func (ac *Config) CommonLogFormat(req *http.Request, statusCode int, byteSize int64) string
- func (ac *Config) DataToClient(w http.ResponseWriter, req *http.Request, filename string, data []byte)
- func (ac *Config) DatabaseBackend() (pinterface.IPermissions, error)
- func (ac *Config) DirPage(w http.ResponseWriter, req *http.Request, ...)
- func (ac *Config) DirectoryListing(w http.ResponseWriter, req *http.Request, rootdir, dirname, theme string)
- func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, luaDataFilename string)
- func (ac *Config) GCSSPage(w http.ResponseWriter, req *http.Request, filename string, gcssdata []byte)
- func (ac *Config) GenerateShutdownFunction(gracefulServer *graceful.Server) func()
- func (ac *Config) HyperAppPage(w http.ResponseWriter, req *http.Request, filename string, jsxdata []byte)
- func (ac *Config) Info() string
- func (ac *Config) InsertAutoRefresh(req *http.Request, htmldata []byte) []byte
- func (ac *Config) JSXPage(w http.ResponseWriter, req *http.Request, filename string, jsxdata []byte)
- func (ac *Config) ListenAndServeQUIC(mux http.Handler, justServeRegularHTTP chan bool, servingHTTPS *atomic.Bool)
- func (ac *Config) LoadBasicSystemFunctions(L *lua.LState)
- func (ac *Config) LoadBasicWeb(w http.ResponseWriter, req *http.Request, L *lua.LState, filename string, ...)
- func (ac *Config) LoadCacheFunctions(L *lua.LState)
- func (ac *Config) LoadCommonFunctions(w http.ResponseWriter, req *http.Request, filename string, L *lua.LState, ...)
- func (ac *Config) LoadJFile(L *lua.LState, scriptdir string)
- func (ac *Config) LoadLuaFunctionsForREPL(L *lua.LState, o *textoutput.TextOutput)
- func (ac *Config) LoadLuaHandlerFunctions(L *lua.LState, filename string, mux *http.ServeMux, addDomain bool, ...)
- func (ac *Config) LoadPluginFunctions(L *lua.LState, o *textoutput.TextOutput)
- func (ac *Config) LoadRenderFunctions(w http.ResponseWriter, _ *http.Request, L *lua.LState)
- func (ac *Config) LoadServeFile(w http.ResponseWriter, req *http.Request, L *lua.LState, filename string)
- func (ac *Config) LoadServerConfigFunctions(L *lua.LState, filename string) error
- func (ac *Config) LogAccess(req *http.Request, statusCode int, byteSize int64)
- func (ac *Config) Lua2funcMap(w http.ResponseWriter, req *http.Request, filename, luafilename, ext string, ...)
- func (ac *Config) LuaFunctionMap(w http.ResponseWriter, req *http.Request, luadata []byte, filename string) (template.FuncMap, error)
- func (ac *Config) MarkdownPage(w http.ResponseWriter, req *http.Request, mdContent []byte, filename string)
- func (ac *Config) MustServe(mux *http.ServeMux) error
- func (ac *Config) NewGracefulServer(handler http.Handler, http2support bool, addr string) *graceful.Server
- func (ac *Config) OpenURL(host, cPort string, httpsPrefix bool) error
- func (ac *Config) PongoHandler(w http.ResponseWriter, req *http.Request, filename, ext string)
- func (ac *Config) PongoPage(w http.ResponseWriter, req *http.Request, filename string, pongodata []byte, ...)
- func (ac *Config) PrettyError(w http.ResponseWriter, req *http.Request, filename string, filebytes []byte, ...)
- func (ac *Config) REPL(ready, done chan bool) error
- func (ac *Config) ReadAndLogErrors(w http.ResponseWriter, filename, ext string) (*datablock.DataBlock, error)
- func (ac *Config) RegisterHandlers(mux *http.ServeMux, handlePath, servedir string, addDomain bool)
- func (ac *Config) RunConfiguration(filename string, mux *http.ServeMux, withHandlerFunctions bool) error
- func (ac *Config) RunLua(w http.ResponseWriter, req *http.Request, filename string, flushFunc func(), ...) error
- func (ac *Config) SCSSPage(w http.ResponseWriter, req *http.Request, filename string, scssdata []byte)
- func (ac *Config) Serve(handler http.Handler, done, ready chan bool) error
- func (ac *Config) ServeStaticFile(filename, colonPort string) error
- func (ac *Config) ServerHeaders(w http.ResponseWriter)
- func (ac *Config) SetFileStatCache(fs *datablock.FileStat)
- type DirConfig
- type FutureStatus
- type ReverseProxy
- type ReverseProxyConfig
Constants ¶
const (
// Version number. Stable API within major version numbers.
Version = 2.0
)
Variables ¶
var ( ErrVersion = errors.New("only showing version information") ErrDatabase = errors.New("could not find a usable database backend") )
ErrVersion is returned when the initialization quits because all that is done is showing version information
Functions ¶
func AtShutdown ¶
func AtShutdown(shutdownFunction func())
AtShutdown adds a function to the list of functions that will be ran at shutdown
func InsertScriptTag ¶ added in v1.17.0
InsertScriptTag takes HTML and JS and tries to insert the JS in a good spot, then returns modified HTML. If the JS does not start with "<script>" and ends with "</script>" then those tags are added.
func ReadIgnoreFile ¶ added in v1.17.0
ReadIgnoreFile reads the ignore patterns from the ignore.txt file.
func RecorderToString ¶ added in v1.17.2
func RecorderToString(recorder *httptest.ResponseRecorder) (string, error)
RecorderToString discards the HTTP headers and return the recorder body as a string. Also flushes the recorder.
func ShouldIgnore ¶ added in v1.17.0
ShouldIgnore checks if a given filename should be ignored based on the provided patterns. A warning will be printed if there are errors with an ignore pattern.
func ValidGCSS ¶
ValidGCSS checks if the given data is valid GCSS. The error value is returned on the channel.
func WriteRecorder ¶ added in v1.17.2
func WriteRecorder(w http.ResponseWriter, recorder *httptest.ResponseRecorder) (int64, error)
WriteRecorder writes to a ResponseWriter from a ResponseRecorder. Also flushes the recorder and returns how many bytes were written.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the main structure for the Algernon server. It contains all the state and settings. The order of the fields has been decided by the "fieldalignment" utility.
func (*Config) AmberPage ¶
func (ac *Config) AmberPage(w http.ResponseWriter, req *http.Request, filename string, amberdata []byte, funcs template.FuncMap)
AmberPage the given source bytes (in Amber) converted to HTML, to a writer. The filename is only used in error messages, if any.
func (*Config) ClearCache ¶ added in v1.17.2
func (ac *Config) ClearCache()
ClearCache tries to clear the Ollama client cache and the disk cache
func (*Config) ClientCanGzip ¶
ClientCanGzip checks if the client supports gzip compressed responses
func (*Config) CombinedLogFormat ¶
CombinedLogFormat returns a line with the data that is available at the start of a request handler. The log line is in CLF, similar to the Common log format, but with two extra fields. See also: https://httpd.apache.org/docs/1.3/logs.html#combined
func (*Config) CommonLogFormat ¶
CommonLogFormat returns a line with the data that is available at the start of a request handler. The log line is in NCSA format, the same log format used by Apache. Fields where data is not available are indicated by a "-". See also: https://en.wikipedia.org/wiki/Common_Log_Format
func (*Config) DataToClient ¶
func (ac *Config) DataToClient(w http.ResponseWriter, req *http.Request, filename string, data []byte)
DataToClient is a helper function for sending file data (that might be cached) to a HTTP client
func (*Config) DatabaseBackend ¶
func (ac *Config) DatabaseBackend() (pinterface.IPermissions, error)
DatabaseBackend tries to retrieve a database backend, using one of the available permission middleware packages. It assign a name to dbName (used for the status output) and returns a IPermissions struct.
func (*Config) DirPage ¶
func (ac *Config) DirPage(w http.ResponseWriter, req *http.Request, rootdir, dirname, theme, luaDataFilename string)
DirPage serves a directory, using index.* files, if present. The directory must exist. rootdir is the base directory (can be ".") dirname is the specific directory that is to be served (should never be ".")
func (*Config) DirectoryListing ¶
func (ac *Config) DirectoryListing(w http.ResponseWriter, req *http.Request, rootdir, dirname, theme string)
DirectoryListing serves the given directory as a web page with links the the contents
func (*Config) FilePage ¶
func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, luaDataFilename string)
FilePage tries to serve a single file. The file must exist. Must be given a full filename.
func (*Config) GCSSPage ¶
func (ac *Config) GCSSPage(w http.ResponseWriter, req *http.Request, filename string, gcssdata []byte)
GCSSPage writes the given source bytes (in GCSS) converted to CSS, to a writer. The filename is only used in the error message, if any.
func (*Config) GenerateShutdownFunction ¶
GenerateShutdownFunction generates a function that will run the postponed shutdown functions. Note that gracefulServer can be nil. It's only used for finding out if the server was interrupted (ctrl-c or killed, SIGINT/SIGTERM)
func (*Config) HyperAppPage ¶
func (ac *Config) HyperAppPage(w http.ResponseWriter, req *http.Request, filename string, jsxdata []byte)
HyperAppPage writes the given source bytes (in JSX for HyperApp) converted to JS, to a writer. The filename is only used in the error message, if any.
func (*Config) InsertAutoRefresh ¶
InsertAutoRefresh inserts JavaScript code to the page that makes the page refresh itself when the source files changes. The JavaScript depends on the event server being available. If JavaScript can not be inserted, return the original data. Assumes that the given htmldata is actually HTML (looks for body/head/html tags when inserting a script tag)
func (*Config) JSXPage ¶
func (ac *Config) JSXPage(w http.ResponseWriter, req *http.Request, filename string, jsxdata []byte)
JSXPage writes the given source bytes (in JSX) converted to JS, to a writer. The filename is only used in the error message, if any.
func (*Config) ListenAndServeQUIC ¶
func (ac *Config) ListenAndServeQUIC(mux http.Handler, justServeRegularHTTP chan bool, servingHTTPS *atomic.Bool)
ListenAndServeQUIC attempts to serve the given http.Handler over QUIC/HTTP3, then reports back any errors when done serving.
func (*Config) LoadBasicSystemFunctions ¶
LoadBasicSystemFunctions loads functions related to logging, markdown and the current server directory into the given Lua state
func (*Config) LoadBasicWeb ¶
func (ac *Config) LoadBasicWeb(w http.ResponseWriter, req *http.Request, L *lua.LState, filename string, flushFunc func(), httpStatus *FutureStatus)
LoadBasicWeb loads functions related to handling requests, outputting data to the browser, setting headers, pretty printing and dealing with the directory where files are being served, into the given Lua state.
func (*Config) LoadCacheFunctions ¶
LoadCacheFunctions loads functions related to caching into the given Lua state
func (*Config) LoadCommonFunctions ¶
func (ac *Config) LoadCommonFunctions(w http.ResponseWriter, req *http.Request, filename string, L *lua.LState, flushFunc func(), httpStatus *FutureStatus)
LoadCommonFunctions adds most of the available Lua functions in algernon to the given Lua state struct
func (*Config) LoadJFile ¶
LoadJFile makes functions related to building a library of Lua code available
func (*Config) LoadLuaFunctionsForREPL ¶
func (ac *Config) LoadLuaFunctionsForREPL(L *lua.LState, o *textoutput.TextOutput)
LoadLuaFunctionsForREPL exports the various Lua functions that might be needed in the REPL
func (*Config) LoadLuaHandlerFunctions ¶
func (ac *Config) LoadLuaHandlerFunctions(L *lua.LState, filename string, mux *http.ServeMux, addDomain bool, httpStatus *FutureStatus, theme string)
LoadLuaHandlerFunctions makes functions related to handling HTTP requests available to Lua scripts
func (*Config) LoadPluginFunctions ¶
func (ac *Config) LoadPluginFunctions(L *lua.LState, o *textoutput.TextOutput)
LoadPluginFunctions takes a Lua state and a TextOutput (the TextOutput struct should be nil if not in a REPL)
func (*Config) LoadRenderFunctions ¶
LoadRenderFunctions adds functions related to rendering text to the given Lua state struct
func (*Config) LoadServeFile ¶
func (ac *Config) LoadServeFile(w http.ResponseWriter, req *http.Request, L *lua.LState, filename string)
LoadServeFile exposes functions for serving other files to Lua
func (*Config) LoadServerConfigFunctions ¶
LoadServerConfigFunctions makes functions related to server configuration and permissions available to the given Lua struct.
func (*Config) LogAccess ¶
LogAccess creates one entry in the access log, given a http.Request, a HTTP status code and the amount of bytes that have been transferred.
func (*Config) Lua2funcMap ¶
func (ac *Config) Lua2funcMap(w http.ResponseWriter, req *http.Request, filename, luafilename, ext string, errChan chan error, funcMapChan chan template.FuncMap)
Lua2funcMap runs in a Lua file and returns the functions as a template.FuncMap (or an error)
func (*Config) LuaFunctionMap ¶
func (ac *Config) LuaFunctionMap(w http.ResponseWriter, req *http.Request, luadata []byte, filename string) (template.FuncMap, error)
LuaFunctionMap returns the functions available in the given Lua code as functions in a map that can be used by templates.
Note that the lua functions must only accept and return strings and that only the first returned value will be accessible. The Lua functions may take an optional number of arguments.
func (*Config) MarkdownPage ¶
func (ac *Config) MarkdownPage(w http.ResponseWriter, req *http.Request, mdContent []byte, filename string)
MarkdownPage write the given source bytes as markdown wrapped in HTML to a writer, with a title
func (*Config) NewGracefulServer ¶
func (ac *Config) NewGracefulServer(handler http.Handler, http2support bool, addr string) *graceful.Server
NewGracefulServer creates a new graceful server configuration
func (*Config) PongoHandler ¶
PongoHandler renders and serves a Pongo2 template
func (*Config) PongoPage ¶
func (ac *Config) PongoPage(w http.ResponseWriter, req *http.Request, filename string, pongodata []byte, funcs template.FuncMap)
PongoPage write the given source bytes (ina Pongo2) converted to HTML, to a writer. The filename is only used in error messages, if any.
func (*Config) PrettyError ¶
func (ac *Config) PrettyError(w http.ResponseWriter, req *http.Request, filename string, filebytes []byte, errormessage, lang string)
PrettyError serves an informative error page to the user
func (*Config) REPL ¶
REPL provides a "Read Eval Print" loop for interacting with Lua. A variety of functions are exposed to the Lua state.
func (*Config) ReadAndLogErrors ¶
func (ac *Config) ReadAndLogErrors(w http.ResponseWriter, filename, ext string) (*datablock.DataBlock, error)
ReadAndLogErrors tries to read a file, and logs an error if it could not be read
func (*Config) RegisterHandlers ¶
RegisterHandlers configures the given mutex and request limiter to handle HTTP requests
func (*Config) RunConfiguration ¶
func (ac *Config) RunConfiguration(filename string, mux *http.ServeMux, withHandlerFunctions bool) error
RunConfiguration runs a Lua file as a configuration script. Also has access to the userstate and permissions. Returns an error if there was a problem with running the lua script, otherwise nil. perm can be nil, but then several Lua functions will not be exposed.
The idea is not to change the Lua struct or the luapool, but to set the configuration variables with the given Lua configuration script.
luaHandler is a flag that lets Lua functions like "handle" and "servedir" be available or not.
func (*Config) RunLua ¶
func (ac *Config) RunLua(w http.ResponseWriter, req *http.Request, filename string, flushFunc func(), fust *FutureStatus) error
RunLua uses a Lua file as the HTTP handler. Also has access to the userstate and permissions. Returns an error if there was a problem with running the lua script, otherwise nil.
func (*Config) SCSSPage ¶
func (ac *Config) SCSSPage(w http.ResponseWriter, req *http.Request, filename string, scssdata []byte)
SCSSPage writes the given source bytes (in SCSS) converted to CSS, to a writer. The filename is only used in the error message, if any.
func (*Config) Serve ¶
Serve HTTP, HTTP/2 and/or HTTPS. Returns an error if unable to serve, or nil when done serving.
func (*Config) ServeStaticFile ¶
ServeStaticFile is a convenience function for serving only a single file. It can be used as a quick and easy way to view a README.md file. Will also serve local images if the resulting HTML contains them.
func (*Config) ServerHeaders ¶
func (ac *Config) ServerHeaders(w http.ResponseWriter)
ServerHeaders sets the HTTP headers that are set before anything else
func (*Config) SetFileStatCache ¶
SetFileStatCache can be used to set a different FileStat cache than the default one
type FutureStatus ¶
type FutureStatus struct {
// contains filtered or unexported fields
}
FutureStatus is useful when redirecting in combination with writing to a buffer before writing to a client. May contain more fields in the future.
type ReverseProxy ¶ added in v1.15.0
ReverseProxy holds which path prefix (like "/api") should be sent where (like "http://localhost:8080")
func (*ReverseProxy) DoProxyPass ¶ added in v1.15.0
DoProxyPass tries to proxy the given http.Request to where the ReverseProxy points
type ReverseProxyConfig ¶ added in v1.15.0
type ReverseProxyConfig struct { ReverseProxies []ReverseProxy // contains filtered or unexported fields }
ReverseProxyConfig holds several "path prefix --> URL" ReverseProxy structs, together with structures that speeds up the prefix matching.
func NewReverseProxyConfig ¶ added in v1.15.0
func NewReverseProxyConfig() *ReverseProxyConfig
NewReverseProxyConfig creates a new and empty ReverseProxyConfig struct
func (*ReverseProxyConfig) Add ¶ added in v1.15.0
func (rc *ReverseProxyConfig) Add(rp *ReverseProxy)
Add can add a ReverseProxy and will also (re-)initialize the internal proxy matcher
func (*ReverseProxyConfig) FindMatchingReverseProxy ¶ added in v1.15.0
func (rc *ReverseProxyConfig) FindMatchingReverseProxy(path string) *ReverseProxy
FindMatchingReverseProxy checks if the given URL path should be proxied
func (*ReverseProxyConfig) Init ¶ added in v1.15.0
func (rc *ReverseProxyConfig) Init()
Init prepares the proxyMatcher and prefix2rproxy fields according to the ReverseProxy structs
Source Files
¶
- access.go
- basic.go
- between.go
- cache.go
- config.go
- dirhandler.go
- flags.go
- funcmap.go
- handlers.go
- help.go
- hyperapp.go
- ignore.go
- jsonfile.go
- lua.go
- luahandler.go
- notrace.go
- plugin.go
- prettyerror.go
- quic_enabled.go
- recorders.go
- rendering.go
- repl.go
- revproxy.go
- serve.go
- servelua.go
- serverconf.go
- sse.go
- static.go
- url.go