server

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(handler http.Handler) error

ListenAndServe starts an HTTP server using either FastCGI or standard HTTP, depending on the environment.

Precedence:

  1. 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).
  2. 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").
  3. 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

func LogError(ctx context.Context, format string, args ...any)

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

func LogInfo(ctx context.Context, format string, args ...any)

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

func LogWarn(ctx context.Context, format string, args ...any)

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:

  1. <domain.ConfigDir>/<app> — PAC layout (CONFIG_BASE_PATH honored for dev).
  2. $XDG_CONFIG_HOME/<app>/<app>.{ext}, then $XDG_CONFIG_HOME/<app>.{ext} (or $HOME/.config fallback).
  3. $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

func RequestLogger() func(next http.Handler) http.Handler

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.

Jump to

Keyboard shortcuts

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