datapagesgen

package
v0.0.0-...-6d7d20a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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

func (s *Server) ListenAndServe(
	ctx context.Context,
	addr string,
) error

ListenAndServe starts the HTTP server.

The provided context controls graceful shutdown.

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(
	ctx context.Context,
	addr, certFile, keyFile string,
) error

ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down all server components.

type ServerOption

type ServerOption func(*Server) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL