config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config resolves the API key and reads/writes the CLI config file.

Index

Constants

View Source
const EnvAPIKey = "DEMOGRAFIX_API_KEY"

EnvAPIKey is the environment variable consulted for the API key.

Variables

View Source
var ErrNoAPIKey = errors.New("no API key configured; run `demografix login` or set DEMOGRAFIX_API_KEY")

ErrNoAPIKey is returned when no key is found in any source. The CLI has no keyless mode.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the config file path, honoring XDG_CONFIG_HOME and falling back to ~/.config on every platform.

func Save

func Save(path string, c Config) error

Save writes the config atomically (temp file + rename), with the directory at 0700 and the file at 0600. The key is never passed on a command line.

Types

type Config

type Config struct {
	APIKey string `toml:"api_key"`
}

Config is the on-disk CLI configuration.

func Load

func Load(path string) (Config, error)

Load reads the config file. A missing file surfaces as os.ErrNotExist.

type Getenv

type Getenv func(string) string

Getenv reads an environment variable; injectable for testing.

type Resolved

type Resolved struct {
	Key    string
	Source Source
}

Resolved is a resolved API key plus where it came from.

func ResolveAPIKey

func ResolveAPIKey(getenv Getenv, configPath string) (Resolved, error)

ResolveAPIKey applies the precedence DEMOGRAFIX_API_KEY > config file. It returns ErrNoAPIKey when neither resolves — there is no keyless fallback.

type Source

type Source int

Source identifies where a resolved API key came from.

const (
	SourceNone Source = iota
	SourceEnv
	SourceConfig
)

Jump to

Keyboard shortcuts

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