Documentation
¶
Overview ¶
Package server provides HTTP/FastCGI server plumbing for config-mate apps.
It is environment-aware but not environment-bound:
- ListenAndServe honours FCGI_LISTEN first (so a Caddy reverse proxy with `transport fastcgi` works in dev without faking the Hostsharing tree), then core.IsFCGI for the real Hostsharing FastCGI case, then plain HTTP for everything else.
- RequestLogger writes per-domain log files when running under Hostsharing FastCGI and to stdout otherwise.
- ReadInConfig loads application configuration with sensible precedence across cwd, per-domain config dir, XDG, and $HOME/.<app>.
Everything in this package works on Hostsharing + dev AND on VM/Root + dev profiles. It depends on core (env-agnostic helpers) and hostsharing only for path-derived log file resolution.
Index ¶
- func ListenAndServe(handler http.Handler) error
- func LogError(ctx context.Context, format string, args ...any)
- func LogInfo(ctx context.Context, format string, args ...any)
- func LogWarn(ctx context.Context, format string, args ...any)
- func ReadInConfig(rawVal any, fs ...mapstructure.DecodeHookFunc) error
- func RequestLogger() func(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe starts an HTTP server using either FastCGI or standard HTTP, depending on the environment.
Precedence:
- FCGI_LISTEN env var → FastCGI on that address (lets Caddy `reverse_proxy` + `transport fastcgi` work in dev where the binary is NOT under a fastcgi/ parent directory).
- core.IsFCGI() → FastCGI on stdin/stdout (Hostsharing's Apache alias /fastcgi-bin/ invokes us from …/doms/<host>/fastcgi/, so the parent dir's base name is "fastcgi" or "fastcgi-ssl").
- Otherwise plain HTTP on the address resolved by [listenAddr]: ADDR (e.g. "127.0.0.1:9000") → PORT (bare port, e.g. "8080") → default ":9000".
func LogError ¶
LogError logs an error-level message with the request context. If a request ID is present in the context, it is included in the log record.
func LogInfo ¶
LogInfo logs an information-level message with the request context. If a request ID is present in the context, it is included in the log record.
func LogWarn ¶
LogWarn logs a warning-level message with the request context. If a request ID is present in the context, it is included in the log record.
func ReadInConfig ¶
func ReadInConfig(rawVal any, fs ...mapstructure.DecodeHookFunc) error
ReadInConfig loads config into rawVal. App name: core.ServiceName. Missing file is not an error: rawVal keeps its zero values plus any prior viper.SetDefault calls (viper ignores mapstructure `default:` tags).
Search order:
- <domain.ConfigDir>/<app> — PAC layout (CONFIG_BASE_PATH honored for dev).
- $XDG_CONFIG_HOME/<app>/<app>.{ext}, then $XDG_CONFIG_HOME/<app>.{ext} (or $HOME/.config fallback).
- $HOME/.<app> (legacy).
File basename must equal <appName>. Extensions: yaml, yml, json, toml, properties, props, prop, hcl, tfvars, dotenv, env, ini; extensionless <appName> also works because SetConfigType("yaml") is set.
rawVal must be a pointer. fs adds mapstructure decode hooks; when empty, defaults are Base64StringToBytesHookFunc(Std, URL), StringToTimeDurationHookFunc, StringToSliceHookFunc(",").
func RequestLogger ¶
RequestLogger returns an HTTP middleware that logs requests using structured logging. It sets up a JSON logger configured for Google Cloud Logging schema, and logs request/response details including optional requestID from the request context. Certain static asset types (css, js, fonts, etc.) are excluded from logging.
Types ¶
This section is empty.