config

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearHostToken

func ClearHostToken(host string) error

ClearHostToken removes the token for a specific host. Returns nil if the host is not in the config.

func ConfigDir

func ConfigDir() string

ConfigDir returns the directory where kh stores its configuration files. Defaults to ~/.config/kh; respects $XDG_CONFIG_HOME if set.

func ConfigFile

func ConfigFile() string

ConfigFile returns the full path to config.yml.

func HostsFile

func HostsFile() string

HostsFile returns the full path to hosts.yml.

func SetHostToken

func SetHostToken(host, token string) error

SetHostToken updates the token for a specific host in the hosts config. If the host entry doesn't exist, it creates one.

func StateDir

func StateDir() string

StateDir returns the directory where kh stores runtime state. Defaults to ~/.local/state/kh; respects $XDG_STATE_HOME if set.

func WriteConfig

func WriteConfig(cfg Config) error

WriteConfig serialises cfg to ConfigFile(), creating the directory if needed.

func WriteHosts

func WriteHosts(cfg HostsConfig) error

WriteHosts serialises cfg to HostsFile(), creating the directory if needed.

Types

type Config

type Config struct {
	ConfigVersion string `yaml:"config_version"`
	DefaultHost   string `yaml:"default_host,omitempty"`
}

Config holds the top-level application configuration stored in config.yml.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with built-in defaults applied.

func ReadConfig

func ReadConfig() (Config, error)

ReadConfig reads ConfigFile() and returns the parsed Config. If the file does not exist, it returns DefaultConfig() without error.

type HostConfig

type HostConfig struct {
	User    string            `yaml:"user,omitempty"`
	Token   string            `yaml:"token,omitempty"`
	Headers map[string]string `yaml:"headers,omitempty"`
}

HostConfig holds per-host authentication and connection details.

type HostsConfig

type HostsConfig struct {
	Hosts         map[string]HostConfig `yaml:"hosts,omitempty"`
	DefaultHost   string                `yaml:"default_host,omitempty"`
	ConfigVersion string                `yaml:"config_version,omitempty"`
}

HostsConfig is the top-level structure for hosts.yml.

func ReadHosts

func ReadHosts() (HostsConfig, error)

ReadHosts reads HostsFile() and returns the parsed HostsConfig. If the file does not exist, it returns an empty HostsConfig without error.

func (*HostsConfig) ActiveHost

func (h *HostsConfig) ActiveHost(flagHost, envHost string) string

ActiveHost resolves the active host using the priority chain: flagHost > envHost > h.DefaultHost > config.yml DefaultHost > "app.keeperhub.com"

func (*HostsConfig) HostEntry

func (h *HostsConfig) HostEntry(hostname string) (HostConfig, bool)

HostEntry looks up the HostConfig for the given hostname. Returns the entry and true if found, or an empty HostConfig and false otherwise.

Jump to

Keyboard shortcuts

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