config

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config provides small dependency-free production configuration helpers for fh applications. It intentionally avoids replacing user config systems; it gives deployments a safe baseline with env overrides and duration parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApp

func NewApp(c Config) (*fh.App, error)

func RequireSecretString

func RequireSecretString(valueEnv, fileEnv string) (string, error)

RequireSecretString resolves a secret and fails when neither source is configured. It is useful for production-only credentials and private keys.

func SecretString

func SecretString(valueEnv, fileEnv string) (string, error)

SecretString resolves one secret at startup. A mounted secret file is preferred because environment values may be exposed through process inspection, crash reports, and child-process inheritance. Direct environment values remain supported for compatibility, but configuring both sources is rejected so key rotation and deployment mistakes fail closed.

SecretString does not cache values or watch files. Call it during startup and retain the decoded key/credential in the component that consumes it.

Types

type Config

type Config struct {
	Server        Server        `json:"server"`
	StartupBanner StartupBanner `json:"startup_banner"`
	Reliability   Reliability   `json:"reliability"`
}

func ApplyEnv

func ApplyEnv(c Config, prefix string) (Config, error)

ApplyEnv overlays values from environment variables using the supplied prefix. Example with prefix FH: FH_ADDR, FH_READ_TIMEOUT, FH_RELIABILITY_ENABLED.

func LoadJSON

func LoadJSON(r io.Reader) (Config, error)

func LoadJSONFile

func LoadJSONFile(path string) (Config, error)

func (Config) AppConfig

func (c Config) AppConfig() (fh.Config, error)

func (Config) Validate

func (c Config) Validate() error

type Reliability

type Reliability struct {
	Enabled     bool   `json:"enabled"`
	DataDir     string `json:"data_dir"`
	QueueDir    string `json:"queue_dir"`
	Workers     int    `json:"workers"`
	MaxAttempts int    `json:"max_attempts"`
}

type Server

type Server struct {
	Addr                string `json:"addr"`
	SecureByDefault     bool   `json:"secure_by_default"`
	ReadTimeout         string `json:"read_timeout"`
	ReadHeaderTimeout   string `json:"read_header_timeout"`
	RequestBodyTimeout  string `json:"request_body_timeout"`
	WriteTimeout        string `json:"write_timeout"`
	HandlerTimeout      string `json:"handler_timeout"`
	IdleTimeout         string `json:"idle_timeout"`
	TLSHandshakeTimeout string `json:"tls_handshake_timeout"`
	HTTP2IdleTimeout    string `json:"http2_idle_timeout"`
	MaxConnections      int    `json:"max_connections"`
	MaxConnectionsPerIP int    `json:"max_connections_per_ip"`
	MaxRequestBodySize  int    `json:"max_request_body_size"`
	MaxHeaderListSize   int    `json:"max_header_list_size"`
	MaxHeaderCount      int    `json:"max_header_count"`
	MaxRequestLineSize  int    `json:"max_request_line_size"`
	DisableHTTP2        bool   `json:"disable_http2"`
	DisableH2C          bool   `json:"disable_h2c"`
	Debug               bool   `json:"debug"`
	Environment         string `json:"environment"`
}

type StartupBanner

type StartupBanner struct {
	Disabled bool   `json:"disabled"`
	Name     string `json:"name"`
	Version  string `json:"version"`
	Subtitle string `json:"subtitle"`
	Scheme   string `json:"scheme"`
	Address  string `json:"address"`
	ASCIIArt string `json:"ascii_art"`
	Color    bool   `json:"color"`
}

Jump to

Keyboard shortcuts

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