Documentation ¶
Index ¶
- func LogRequests(logger *slog.Logger) middleware.Middleware
- func NewHandler(max slog.Level, tag string, out io.Writer) slog.Handler
- func NewLogger(max slog.Level, tag string, out io.Writer) *slog.Logger
- type Component
- type Config
- type Page
- type PageMeta
- type RenderData
- type RenderFunc
- type Server
- type SyslogHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogRequests ¶
func LogRequests(logger *slog.Logger) middleware.Middleware
Types ¶
type Component ¶
type Component struct { Name string File string Components []*Component // OnLoad transforms whatever input data is passed to the Component into a different data to use for rendering OnLoad func(input any) any // contains filtered or unexported fields }
A Component is renderable on any data. Typically this is a sub-item contained in a page and rendered through "render".
type Config ¶
type Config struct { // Setting Debug to true sets the server to debug, increasing log verbosity and recompiling pages on refresh. Debug bool // RootDir is the base directory to serve files from. RootDir string // PublicDir is the base directory of public files, and is always served at the root /. Public files shouldn't match the paths of any Pages. // Leaving PublicDir empty will not server any public files. PublicDir string // Pages are all of the pages you want to render in the website. Pages []*Page // LogLevel is the max log level for the server. Defaults to slog.LevelInfo. // If Debug is set to true, this is *always* overridden to slog.LevelDebug. LogLevel slog.Level }
Config is the base configuration for a Server. It's not explicitly required that you build a server this way, but I think it's handy.
type Page ¶
type Page struct { Location string Title string Icon string Styles []string File string Components []*Component // OnLoad transforms the input request into arbitrary data for Render. OnLoad func(req *http.Request) any // contains filtered or unexported fields }
Pages are components that are Renderable on an *http.Request. These don't technically have to be HTML, but they usually are.
type RenderData ¶
type RenderData struct { Components map[string]RenderFunc PageMeta PageMeta Data any }
RenderData is the base structure passed to *all* pages and components on render.
type RenderFunc ¶
RenderFunc is any function that renders arbitrary data to a string.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the base-level object for serving up the website. It manages pages, the public directory, and logging.
func (*Server) Compile ¶
Compile prepares the server to handle HTTP requests. Run fails if called before Compile, so make sure to always do this.
func (*Server) Log ¶
Log aliases slog.Logger.Log for the server's current logger. Currently, servers always use rfc3164 format.
func (*Server) Public ¶
Public prepares to serve a directory at the root URI. Public files are always served after any page locations, so given a public file page.html and a page at location page.html, the page is *always* loaded.