Documentation
¶
Overview ¶
Package config loads runtime configuration from a JSON file, with environment variables taking precedence. Currently it carries the PostgreSQL connection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseDir ¶
func BaseDir() string
BaseDir is the directory that anchors all runtime artifacts (config.json and the data/ store). It is the directory the running binary lives in, so a distributed executable keeps its files next to itself on any OS (Windows, Linux, …) regardless of the working directory it is launched from.
When launched via `go run`, the binary is throwaway: it sits either in a temp build dir (cache miss → fresh link) OR straight inside the Go build cache (cache hit → run from $GOCACHE/.../...-d). We detect both and fall back to the current working directory so dev artifacts (data/, transcripts) and config resolve against the project dir, not the throwaway binary's location.
func Path ¶
func Path() string
Path returns the config file path. Resolution order:
- env ARTEX_CONFIG (explicit override)
- ./config.json in the current working directory (running from the project dir — robust no matter where `go run` placed the temp/cached binary)
- config.json next to the executable (a distributed binary keeps it beside)
The first existing file wins. If none exist, the CWD path is returned so the "not found" message points at the project dir the user most likely expected.
func PostgresDSN ¶
PostgresDSN resolves the connection string with precedence:
env ARTEX_PG_DSN > config file (database.dsn, or assembled from fields)
There is NO built-in fallback: when neither source supplies a database config, it returns an error naming the config path it inspected, so startup fails loudly instead of silently connecting to a wrong default. source describes where the DSN came from (for startup logging).
Types ¶
type Database ¶
type Database struct {
DSN string `json:"dsn"`
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
DBName string `json:"dbname"`
SSLMode string `json:"sslmode"`
}
Database is the PostgreSQL connection config. Either set DSN directly, or set the component fields and a DSN is assembled from them.