config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config loads and saves the CLI's configuration: named contexts in config.yaml (shareable) and secrets in credentials.yaml (0600), both under $XDG_CONFIG_HOME/webtor (~/.config/webtor by default). The WEBTOR_* env vars override everything, so CI can run without any files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() string

Dir returns the configuration directory.

func Exists

func Exists() bool

Exists reports whether a config file is present.

func Load

func Load() (*Config, Credentials, error)

Load reads config.yaml and credentials.yaml. A missing config is an error; missing credentials are not (an empty set is returned).

func Save

func Save(cfg *Config, creds Credentials) error

Save writes both files, creating the directory as needed. credentials.yaml is written 0600 — it holds keys.

func SetCredentials

func SetCredentials(name string, c ContextCredentials) error

SetCredentials updates one context's secrets on disk, preserving the rest.

Types

type BackendName

type BackendName string

BackendName is the config-file spelling of a backend kind.

const (
	BackendWebUI    BackendName = "webui"
	BackendRapidAPI BackendName = "rapidapi"
	BackendDirect   BackendName = "direct"
)

type Config

type Config struct {
	Current  string             `yaml:"current"`
	Contexts map[string]Context `yaml:"contexts"`
}

Config is config.yaml: the contexts and which one is current.

type Context

type Context struct {
	Backend BackendName `yaml:"backend"`
	// BaseURL overrides the backend's default endpoint. Required for direct.
	BaseURL string `yaml:"base_url,omitempty"`
}

Context is one named backend configuration.

type ContextCredentials

type ContextCredentials struct {
	// APIKey is the web-ui API key, the RapidAPI key, or direct's
	// pass-through api-key, depending on the context's backend.
	APIKey string `yaml:"api_key,omitempty"`
	// Token is direct's pass-through JWT.
	Token string `yaml:"token,omitempty"`
}

ContextCredentials are the secrets of one context.

type Credentials

type Credentials map[string]*ContextCredentials

Credentials is credentials.yaml: per-context secrets, kept out of the shareable config file.

type Resolved

type Resolved struct {
	Name    string
	Context Context
	Creds   ContextCredentials
	// FromEnv marks the config-less WEBTOR_BACKEND mode: nothing is stored
	// on disk for this configuration.
	FromEnv bool
}

Resolved is a fully resolved runtime configuration: the chosen context plus its secrets, after env overrides.

func Resolve

func Resolve(contextFlag string) (*Resolved, error)

Resolve picks the runtime configuration: when WEBTOR_BACKEND is set, the WEBTOR_* env vars fully describe it and no files are needed (config-less CI mode); otherwise the named context (flag > config current) is loaded from the files, and env vars are ignored.

func (*Resolved) Backend

func (r *Resolved) Backend() (webtor.Backend, error)

Backend constructs the SDK backend for the resolved configuration.

Jump to

Keyboard shortcuts

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