Documentation
¶
Index ¶
Constants ¶
const ( DefaultHTTPReadTimeout = 30 * time.Second DefaultHTTPReadHeaderTimeout = 5 * time.Second DefaultHTTPWriteTimeout = 0 // SSE needs this disabled. DefaultHTTPIdleTimeout = 60 * time.Second DefaultHTTPMaxHeaderBytes = 1 << 20 // 1 MB // DefaultDatastarJSSrc is the default URL for the Datastar JavaScript bundle. DefaultDatastarJSSrc = "https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.1/bundles/datastar.js" )
const DefaultBodySizeLimit = 1024 * 1024 // 1 MiB
Variables ¶
This section is empty.
Functions ¶
func IsDevMode ¶
func IsDevMode() bool
IsDevMode returns true when in the development environment. Returns false for production environments.
func MessageBrokerStreamSubjects ¶
func MessageBrokerStreamSubjects() []string
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer( app *app.App, messageBroker msgbroker.MessageBroker, opts ...ServerOption, ) *Server
NewServer creates a new server instance. Supported options:
- WithMiddleware
- WithHTTPServer
- WithAssets
- WithDatastarJS
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server.
The provided context controls graceful shutdown.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections.
type ServerOption ¶
ServerOption is a functional option for configuring Server
func WithAssets ¶
func WithAssets(fsys embed.FS) ServerOption
WithAssets enables serving static asset files at assets.URLPrefix. Pass the embed.FS that contains your static files (e.g. with //go:embed static/* in your app package). The embed.FS subdirectory (assets.Dir) is extracted automatically.
In dev mode (IsDevMode), files are served from disk (assets.DevDir) for live reloading without recompilation.
func WithDatastarJS ¶
func WithDatastarJS(src string) ServerOption
WithDatastarJS sets a custom URL for the Datastar JavaScript bundle. Defaults to DefaultDatastarJSSrc if not set.
func WithHTTPServer ¶
func WithHTTPServer(server *http.Server) ServerOption
WithHTTPServer sets a custom HTTP server. The Addr and Handler fields are always overwritten.
func WithLogger ¶
func WithLogger(l *slog.Logger) ServerOption
WithLogger sets a custom error logger. Consider setting level DEBUG when IsDevMode() returns true.
func WithMiddleware ¶
func WithMiddleware(middleware func(http.Handler) http.Handler) ServerOption
WithMiddleware adds a custom middleware.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package action provides generators for datastar action attribute expressions.
|
Package action provides generators for datastar action attribute expressions. |
|
Package assets provides constants for embedded static file serving.
|
Package assets provides constants for embedded static file serving. |
|
Package href provides generators for datastar anchor hypertext references.
|
Package href provides generators for datastar anchor hypertext references. |
|
Package httperr provides sentinel errors for action handlers.
|
Package httperr provides sentinel errors for action handlers. |