algernon: Index | Files

package engine

import ""

Package engine provides the server configuration struct and several functions for serving files over HTTP


Package Files

basic.go cache.go config.go dirhandler.go flags.go funcmap.go handlers.go hyperapp.go jsonfile.go lua.go luahandler.go mime.go plugin.go prettyerror.go rendering.go repl.go serve.go servelua.go serverconf.go sse.go static.go url.go


const Version = 2.0

Version number. Stable API within major version numbers.


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

func AtShutdown Uses

func AtShutdown(shutdownFunction func())

AtShutdown adds a function to the list of functions that will be ran at shutdown

func DataToClientModernBrowsers Uses

func DataToClientModernBrowsers(w http.ResponseWriter, req *http.Request, filename string, data []byte)

DataToClientModernBrowsers is a helper function for sending file data (that might be cached) to a HTTP client

func ValidGCSS Uses

func ValidGCSS(gcssdata []byte, errorReturn chan error)

ValidGCSS checks if the given data is valid GCSS. The error value is returned on the channel.

type Config Uses

type Config struct {
    // contains filtered or unexported fields

Config is the main structure for the Algernon server. It contains all the state and settings.

func New Uses

func New(versionString, description string) (*Config, error)

New creates a new server configuration based using the default values

func (*Config) AmberPage Uses

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) ClientCanGzip Uses

func (ac *Config) ClientCanGzip(req *http.Request) bool

ClientCanGzip checks if the client supports gzip compressed responses

func (*Config) Close Uses

func (ac *Config) Close()

Close removes the temporary directory

func (*Config) DataToClient Uses

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 Uses

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 Uses

func (ac *Config) DirPage(w http.ResponseWriter, req *http.Request, rootdir, dirname, theme 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 Uses

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 Uses

func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, dataFilename string)

FilePage tries to serve a single file. The file must exist. Must be given a full filename.

func (*Config) GCSSPage Uses

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 Uses

func (ac *Config) GenerateShutdownFunction(gracefulServer *graceful.Server, quicServer *h2quic.Server) func()

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 Uses

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) Info Uses

func (ac *Config) Info() string

Info returns a string with various info about the current configuration

func (*Config) InsertAutoRefresh Uses

func (ac *Config) InsertAutoRefresh(req *http.Request, htmldata []byte) []byte

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 Uses

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) LoadBasicSystemFunctions Uses

func (ac *Config) LoadBasicSystemFunctions(L *lua.LState)

LoadBasicSystemFunctions loads functions related to logging, markdown and the current server directory into the given Lua state

func (*Config) LoadBasicWeb Uses

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 Uses

func (ac *Config) LoadCacheFunctions(L *lua.LState)

LoadCacheFunctions loads functions related to caching into the given Lua state

func (*Config) LoadCommonFunctions Uses

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 Uses

func (ac *Config) LoadJFile(L *lua.LState, scriptdir string)

LoadJFile makes functions related to building a library of Lua code available

func (*Config) LoadLuaFunctionsForREPL Uses

func (ac *Config) LoadLuaFunctionsForREPL(L *lua.LState, o *term.TextOutput)

LoadLuaFunctionsForREPL exports the various Lua functions that might be needed in the REPL

func (*Config) LoadLuaHandlerFunctions Uses

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 Uses

func (ac *Config) LoadPluginFunctions(L *lua.LState, o *term.TextOutput)

LoadPluginFunctions takes a Lua state and a TextOutput (the TextOutput struct should be nil if not in a REPL)

func (*Config) LoadRenderFunctions Uses

func (ac *Config) LoadRenderFunctions(w http.ResponseWriter, req *http.Request, L *lua.LState)

LoadRenderFunctions adds functions related to rendering text to the given Lua state struct

func (*Config) LoadServeFile Uses

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 Uses

func (ac *Config) LoadServerConfigFunctions(L *lua.LState, filename string) error

LoadServerConfigFunctions makes functions related to server configuration and permissions available to the given Lua struct.

func (*Config) Lua2funcMap Uses

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 Uses

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 Uses

func (ac *Config) MarkdownPage(w http.ResponseWriter, req *http.Request, data []byte, filename string)

MarkdownPage write the given source bytes as markdown wrapped in HTML to a writer, with a title

func (*Config) MustServe Uses

func (ac *Config) MustServe(mux *http.ServeMux) error

MustServe sets up a server with handlers

func (*Config) NewGracefulServer Uses

func (ac *Config) NewGracefulServer(mux *http.ServeMux, http2support bool, addr string) *graceful.Server

NewGracefulServer creates a new graceful server configuration

func (*Config) OpenURL Uses

func (ac *Config) OpenURL(host, colonPort string, httpsPrefix bool)

OpenURL tries to open an URL with the system browser

func (*Config) PongoHandler Uses

func (ac *Config) PongoHandler(w http.ResponseWriter, req *http.Request, filename, ext string)

PongoHandler renders and serves a Pongo2 template

func (*Config) PongoPage Uses

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 Uses

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 Takes a ResponseWriter, title (can be empty), filename, filebytes, errormessage and programming/scripting/template language (i.e. "lua". Can be empty).

func (*Config) REPL Uses

func (ac *Config) REPL(ready, done chan bool) error

REPL provides a "Read Eval Print" loop for interacting with Lua. A variety of functions are exposed to the Lua state.

func (*Config) ReadAndLogErrors Uses

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 Uses

func (ac *Config) RegisterHandlers(mux *http.ServeMux, handlePath, servedir string, addDomain bool)

RegisterHandlers configures the given mutex and request limiter to handle HTTP requests

func (*Config) RunConfiguration Uses

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 Uses

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 Uses

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 Uses

func (ac *Config) Serve(mux *http.ServeMux, done, ready chan bool) error

Serve HTTP, HTTP/2 and/or HTTPS. Returns an error if unable to serve, or nil when done serving.

func (*Config) ServeStaticFile Uses

func (ac *Config) ServeStaticFile(filename, colonPort string) error

ServeStaticFile is a convenience function for serving only a single file. It can be used as a quick and easy way to view a file.

func (*Config) ServerHeaders Uses

func (ac *Config) ServerHeaders(w http.ResponseWriter)

ServerHeaders sets the HTTP headers that are set before anything else

func (*Config) SetFileStatCache Uses

func (ac *Config) SetFileStatCache(fs *datablock.FileStat)

SetFileStatCache can be used to set a different FileStat cache than the default one

type DirConfig Uses

type DirConfig struct {
    Main struct {
        Title string
        Theme string

DirConfig keeps a directory listing configuration

type FutureStatus Uses

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.

Package engine imports 68 packages (graph) and is imported by 1 packages. Updated 2018-08-16. Refresh now. Tools for package owners.