config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 10 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 stores named profiles and resolves which API key to use.

The saved Webmaster page lists several sites per account, while /web takes no site parameter: the key selects the site. Hence one profile per site.

Index

Constants

View Source
const (
	EnvAPIKey    = "SZWM_API_KEY"
	EnvAPIKeyAlt = "SEZNAM_WEBMASTER_API_KEY"
	EnvProfile   = "SZWM_PROFILE"
	EnvConfigDir = "SZWM_CONFIG_DIR"
	EnvStateDir  = "SZWM_STATE_DIR"
	EnvBaseURL   = "SZWM_BASE_URL"
	EnvOutput    = "SZWM_OUTPUT"
	EnvReadOnly  = "SZWM_READ_ONLY"
)

Environment variables.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the config directory.

func Fingerprint

func Fingerprint(key string) string

Fingerprint returns a stable non-reversible key identifier. It scopes local state and lets agents compare keys without ever seeing them.

func NormalizeSite

func NormalizeSite(s string) string

NormalizeSite strips scheme, www and trailing slash for comparison.

func Path

func Path() (string, error)

Path returns the config file path.

func StateDir

func StateDir() string

StateDir returns the directory for rate-limit and quota state.

Types

type File

type File struct {
	Version        int                `json:"version"`
	DefaultProfile string             `json:"default_profile,omitempty"`
	Profiles       map[string]Profile `json:"profiles"`
}

File is the on-disk config.

func Load

func Load() (*File, error)

Load reads the config; a missing file yields an empty config.

func (*File) Find

func (f *File) Find(ref string) (string, Profile, bool)

Find looks a profile up by name, then by site.

func (*File) Names

func (f *File) Names() []string

Names returns profile names sorted.

func (*File) Save

func (f *File) Save() error

Save writes the config atomically with owner-only permissions.

type Input

type Input struct {
	KeyFile string
	Profile string
	Stdin   func() ([]byte, error)
}

Input carries the explicit choices made on the command line.

type Profile

type Profile struct {
	Key  string `json:"key"`
	Site string `json:"site,omitempty"`
}

Profile is one site's credentials.

type Resolved

type Resolved struct {
	Key    string
	Source Source
}

Resolved is the outcome of key resolution.

func Resolve

func Resolve(in Input) (Resolved, error)

Resolve applies the precedence: --api-key-file, --profile, environment key, SZWM_PROFILE, default profile, the only profile. Finding nothing is not an error here, since many commands work without a key.

type Source

type Source struct {
	Kind    string `json:"kind"` // key-file | profile | env | none
	Name    string `json:"name,omitempty"`
	Profile string `json:"profile,omitempty"`
	Site    string `json:"site,omitempty"`
}

Source says where a key came from. It never contains the key.

Jump to

Keyboard shortcuts

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