config

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

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:

  1. env ARTEX_CONFIG (explicit override)
  2. ./config.json in the current working directory (running from the project dir — robust no matter where `go run` placed the temp/cached binary)
  3. 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

func PostgresDSN() (dsn, source string, err error)

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).

func Redact

func Redact(dsn string) string

String is a redacted view of the resolved DSN (password masked) for logging.

func SkillDir

func SkillDir() string

SkillDir returns the skill root directory with precedence:

env ARTEX_SKILL_DIR  >  config file (skill_dir)  >  BaseDir()/skills

The directory is created if it does not exist.

Types

type Config

type Config struct {
	Database Database `json:"database"`
	SkillDir string   `json:"skill_dir"`
}

Config is the on-disk config file shape.

func Load

func Load() Config

Load reads and parses the config file. A missing/unreadable file yields a zero Config (so callers fall back to defaults) rather than an error.

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.

Jump to

Keyboard shortcuts

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