config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config loads and exposes the ~/.bitgit/config.toml configuration.

Usage:

cfg, err := config.Load()         // reads $BITGIT_HOME/config.toml or ~/.bitgit/config.toml
cfg := config.MustLoad()          // panics on error

The singleton is safe for concurrent read after Load() returns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reset

func Reset()

Reset clears the singleton — for use in tests only.

Types

type Config

type Config struct {
	DefaultRemote string        `toml:"default_remote"`
	Hosts         []HostEntry   `toml:"hosts"`
	Plugins       PluginsConfig `toml:"plugins"`

	// InsecureSkipVerify enables skipping TLS cert validation for all hosts.
	// WARNING: exposes you to MITM attacks. Use only in controlled environments.
	InsecureSkipVerify bool `toml:"insecure_skip_verify"`
	// contains filtered or unexported fields
}

Config is the parsed ~/.bitgit/config.toml.

func Load

func Load() (*Config, error)

Load loads the config exactly once and returns the singleton. Subsequent calls return the cached result.

func MustLoad

func MustLoad() *Config

MustLoad is like Load but panics on error.

func (*Config) Dir

func (c *Config) Dir() string

Dir returns the config directory (e.g. ~/.bitgit).

func (*Config) HostForURL

func (c *Config) HostForURL(rawURL string) *HostEntry

HostForURL finds the first [[hosts]] entry matching the given URL prefix. Returns nil if not found.

func (*Config) PluginsDir

func (c *Config) PluginsDir() string

PluginsDir returns the plugins subdirectory.

func (*Config) ReadToken

func (c *Config) ReadToken(hostType string) (string, error)

ReadToken reads a bearer token for the given host.

Resolution order:

  1. Environment variable (GITHUB_TOKEN for github, BITBUCKET_TOKEN for bitbucket-dc)
  2. token_file path from [[hosts]] entry
  3. Default secrets file: <config-dir>/secrets/<type>.token

The file must be mode 0600; ReadToken returns an error if it is world-readable.

func (*Config) SecretsDir

func (c *Config) SecretsDir() string

SecretsDir returns the secrets subdirectory.

type HostEntry

type HostEntry struct {
	URL       string `toml:"url"`
	Type      string `toml:"type"`       // "github" | "bitbucket-dc"
	TokenFile string `toml:"token_file"` // path to token file
}

HostEntry is a per-host credential block in [[hosts]].

type PluginsConfig

type PluginsConfig struct {
	Disabled []string `toml:"disabled"`
}

PluginsConfig holds the [plugins] section overrides.

Jump to

Keyboard shortcuts

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