config

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config resolves credentials and the environment they point at.

The API key prefix encodes the environment — sk_sandbox_ against sandbox, sk_live_ against production — so there is no separate --env flag that can disagree with the key actually in use. Passing a sandbox key and a production base URL is not a combination worth supporting.

Index

Constants

View Source
const (
	SandboxBaseURL = "https://sandbox-api.bachs.io"
	LiveBaseURL    = "https://api.bachs.io"
)

Variables

View Source
var ErrNoAPIKey = errors.New(
	"not logged in\n" +
		"  run:  bachs login\n" +
		"  CI:   export BACHS_API_KEY=sk_sandbox_...",
)

ErrNoAPIKey is returned when no credential can be found anywhere.

Leads with the browser flow because that is the one that does not put a key in shell history. The env var is listed second for CI, where there is nobody to approve anything.

Functions

func Clear added in v0.2.2

func Clear() (bool, error)

Clear removes the stored credentials.

Reports whether there was anything to remove, so the caller can tell "logged out" from "was not logged in" rather than claiming to have done something it did not. A missing file is not an error: running logout twice should be quiet, not a failure.

func Dir

func Dir() string

Dir is where credentials live. Honours BACHS_CONFIG_DIR for tests and for anyone who keeps config somewhere unusual.

func Path

func Path() string

func Save

func Save(apiKey string) (string, error)

Save writes the key for later commands.

0600 in a 0700 directory. This is a plaintext secret on disk, which is worth being explicit about: the OS keychain would be better, and doing that across macOS, Linux and Windows is enough work to be its own change. Until then the file mode is the whole protection, so it is set deliberately rather than left to the process umask.

Types

type Config

type Config struct {
	APIKey  string
	BaseURL string
}

func Load

func Load(override string) (Config, error)

Load resolves credentials in precedence order: an explicit flag, then BACHS_API_KEY, then the config file.

The env var sits above the file so CI can run without writing one, and below the flag so a one-off invocation can target another account.

func (Config) IsSandbox

func (c Config) IsSandbox() bool

IsSandbox reports whether this key targets sandbox rather than production.

func (Config) Redacted

func (c Config) Redacted() string

Redacted renders the key safe to print. Never log the key itself.

func (Config) WebSocketURL

func (c Config) WebSocketURL() string

WebSocketURL is the forwarding socket for this environment.

Jump to

Keyboard shortcuts

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