Documentation
¶
Overview ¶
Package config provides a go-simpler.org/env configuration table and helpers for working with the list of key/value lists stored in .env files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetEnv ¶
func GetEnv() (requested bool)
GetEnv checks if the first command line argument is "env" and returns whether the environment configuration should be printed.
Return Values ¶
- requested: A boolean indicating true if the 'env' argument was provided, false otherwise.
Expected Behaviour ¶
The function returns true when the first command line argument is "env" (case-insensitive), signalling that the environment configuration should be printed. Otherwise, it returns false.
func HelpRequested ¶
func HelpRequested() (help bool)
HelpRequested determines if the command line arguments indicate a request for help
Return Values ¶
- help: A boolean value indicating true if a help flag was detected in the command line arguments, false otherwise
Expected Behaviour ¶
The function checks the first command line argument for common help flags and returns true if any of them are present. Returns false if no help flag is found
func IdentityRequested ¶ added in v0.8.0
func IdentityRequested() (requested bool)
IdentityRequested checks if the first command line argument is "identity" and returns whether the relay identity should be printed and the program should exit.
Return Values
- requested: true if the 'identity' subcommand was provided, false otherwise.
func PrintEnv ¶
PrintEnv outputs sorted environment key/value pairs from a configuration object to the provided writer
Parameters ¶
cfg: Pointer to the configuration object containing env tags
printer: Destination for the output, typically an io.Writer implementation
Expected Behaviour ¶
Outputs each environment variable derived from the config's struct tags in sorted order, formatted as "key=value\n" to the specified writer
func PrintHelp ¶
PrintHelp prints help information including application version, environment variable configuration, and details about .env file handling to the provided writer
Parameters ¶
cfg: Configuration object containing app name and config directory path
printer: Output destination for the help text
Expected Behaviour ¶
Prints application name and version followed by environment variable configuration details, explains .env file behaviour including automatic loading and custom path options, and displays current configuration values using PrintEnv. Outputs all information to the specified writer
Types ¶
type C ¶
type C struct {
AppName string `env:"ORLY_APP_NAME" usage:"set a name to display on information about the relay" default:"ORLY"`
DataDir string `env:"ORLY_DATA_DIR" usage:"storage location for the event store" default:"~/.local/share/ORLY"`
Listen string `env:"ORLY_LISTEN" default:"0.0.0.0" usage:"network listen address"`
Port int `env:"ORLY_PORT" default:"3334" usage:"port to listen on"`
HealthPort int `env:"ORLY_HEALTH_PORT" default:"0" usage:"optional health check HTTP port; 0 disables"`
EnableShutdown bool `` /* 142-byte string literal not displayed */
LogLevel string `env:"ORLY_LOG_LEVEL" default:"info" usage:"relay log level: fatal error warn info debug trace"`
DBLogLevel string `env:"ORLY_DB_LOG_LEVEL" default:"info" usage:"database log level: fatal error warn info debug trace"`
DBBlockCacheMB int `env:"ORLY_DB_BLOCK_CACHE_MB" default:"512" usage:"Badger block cache size in MB (higher improves read hit ratio)"`
DBIndexCacheMB int `env:"ORLY_DB_INDEX_CACHE_MB" default:"256" usage:"Badger index cache size in MB (improves index lookup performance)"`
LogToStdout bool `env:"ORLY_LOG_TO_STDOUT" default:"false" usage:"log to stdout instead of stderr"`
Pprof string `env:"ORLY_PPROF" usage:"enable pprof in modes: cpu,memory,allocation,heap,block,goroutine,threadcreate,mutex"`
PprofPath string `env:"ORLY_PPROF_PATH" usage:"optional directory to write pprof profiles into (inside container); default is temporary dir"`
PprofHTTP bool `env:"ORLY_PPROF_HTTP" default:"false" usage:"if true, expose net/http/pprof on port 6060"`
OpenPprofWeb bool `env:"ORLY_OPEN_PPROF_WEB" default:"false" usage:"if true, automatically open the pprof web viewer when profiling is enabled"`
IPWhitelist []string `` /* 159-byte string literal not displayed */
IPBlacklist []string `` /* 146-byte string literal not displayed */
Admins []string `env:"ORLY_ADMINS" usage:"comma-separated list of admin npubs"`
Owners []string `` /* 138-byte string literal not displayed */
ACLMode string `env:"ORLY_ACL_MODE" usage:"ACL mode: follows, managed (nip-86), none" default:"none"`
AuthRequired bool `env:"ORLY_AUTH_REQUIRED" usage:"require authentication for all requests (works with managed ACL)" default:"false"`
BootstrapRelays []string `env:"ORLY_BOOTSTRAP_RELAYS" usage:"comma-separated list of bootstrap relay URLs for initial sync"`
NWCUri string `env:"ORLY_NWC_URI" usage:"NWC (Nostr Wallet Connect) connection string for Lightning payments"`
SubscriptionEnabled bool `` /* 139-byte string literal not displayed */
MonthlyPriceSats int64 `env:"ORLY_MONTHLY_PRICE_SATS" default:"6000" usage:"price in satoshis for one month subscription (default ~$2 USD)"`
RelayURL string `env:"ORLY_RELAY_URL" usage:"base URL for the relay dashboard (e.g., https://relay.example.com)"`
RelayAddresses []string `` /* 150-byte string literal not displayed */
FollowListFrequency time.Duration `env:"ORLY_FOLLOW_LIST_FREQUENCY" usage:"how often to fetch admin follow lists (default: 1h)" default:"1h"`
// Web UI and dev mode settings
WebDisableEmbedded bool `env:"ORLY_WEB_DISABLE" default:"false" usage:"disable serving the embedded web UI; useful for hot-reload during development"`
WebDevProxyURL string `` /* 147-byte string literal not displayed */
// Sprocket settings
SprocketEnabled bool `env:"ORLY_SPROCKET_ENABLED" default:"false" usage:"enable sprocket event processing plugin system"`
PolicyEnabled bool `` /* 142-byte string literal not displayed */
}
C holds application configuration settings loaded from environment variables and default values. It defines parameters for app behaviour, storage locations, logging, and network settings used across the relay service.
func New ¶
New creates and initializes a new configuration object for the relay application
Return Values ¶
cfg: A pointer to the initialized configuration struct containing default or environment-provided values
err: An error object that is non-nil if any operation during initialization fails
Expected Behaviour: ¶
Initializes a new configuration instance by loading environment variables and checking for a .env file in the default configuration directory. Sets logging levels based on configuration values and returns the populated configuration or an error if any step fails
type KVSlice ¶
type KVSlice []KV
KVSlice is a sortable slice of key/value pairs, designed for managing configuration data and enabling operations like merging and sorting based on keys.
func EnvKV ¶
EnvKV generates key/value pairs from a configuration object's struct tags
Parameters ¶
- cfg: A configuration object whose struct fields are processed for env tags
Return Values ¶
- m: A KVSlice containing key/value pairs derived from the config's env tags
Expected Behaviour ¶
Processes each field of the config object, extracting values tagged with "env" and converting them to strings. Skips fields without an "env" tag. Handles various value types including strings, integers, booleans, durations, and string slices by joining elements with commas.
func (KVSlice) Compose ¶
Compose merges two KVSlice instances into a new slice where key-value pairs from the second slice override any duplicate keys from the first slice.
Parameters ¶
- kv2: The second KVSlice whose entries will be merged with the receiver.
Return Values ¶
- out: A new KVSlice containing all entries from both slices, with keys from kv2 taking precedence over keys from the receiver.
Expected Behaviour ¶
The method returns a new KVSlice that combines the contents of the receiver and kv2. If any key exists in both slices, the value from kv2 is used. The resulting slice remains sorted by keys as per the KVSlice implementation.
Source Files
¶
- config.go