config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config resolves the CLI home directory and loads config.json.

Index

Constants

View Source
const (
	MinOrderLevel  = 1
	MaxOrderLevel  = 100
	MaxOrderLevels = 9
)

Order-size preset bounds. Each level is a percentage of the funding balance (1..100, where 100 = "max"); MaxOrderLevels caps the count at the number of digit keys (1..9) the order UIs can bind. The list is stored as a plain JSON array, so extending it later needs no schema change and an older binary reads a longer list without error.

Variables

View Source
var Backends = []string{"file", "keychain"}

Backends are the supported keystore backend names.

View Source
var ColorSchemes = []string{"green-red", "red-blue"}

ColorSchemes are the valid persisted tui color-scheme names. They mirror uikit.ColorScheme.String(); config keeps its own copy so it need not import the (charm-dependent) tui/uikit layer. A uikit test pins the two lists together so they cannot drift.

Functions

func Home

func Home(getenv func(string) string) string

Home returns the CLI home directory: $KORBIT_CLI_HOME, else ~/.korbit-cli.

func Path

func Path(home string) string

Path is the config.json path under home.

func SetKeystore

func SetKeystore(home, backend string, log *slog.Logger) error

SetKeystore persists the default-keystore-for-new-keys choice into config.json (the `keystore default` command), leaving every other field (baseUrl, and any field this version doesn't model) exactly as it was.

func SetTUIColorScheme

func SetTUIColorScheme(home, scheme string, log *slog.Logger) error

SetTUIColorScheme persists the tui command's up/down color convention ("green-red" or "red-blue") under config.json's "tui" object, leaving every other field — top-level, and any other key inside "tui" — exactly as it was. The tui command calls it off the UI goroutine when the C key toggles the scheme.

func SetTUIOrderLevels

func SetTUIOrderLevels(home string, levels []int, log *slog.Logger) error

SetTUIOrderLevels persists the tui command's %-of-balance size presets under config.json's "tui" object, leaving every other field alone. The tui command pins the built-in defaults here on first launch.

func ValidBackend

func ValidBackend(name string) bool

ValidBackend reports whether name is a recognized keystore backend. It is the single home for the "is this a real backend" check — callers (the CLI command, the keystore constructors) should use it rather than re-listing Backends.

func ValidColorScheme

func ValidColorScheme(name string) bool

ValidColorScheme reports whether name is a recognized tui color-scheme value.

func ValidOrderLevels

func ValidOrderLevels(levels []int) bool

ValidOrderLevels reports whether levels is an acceptable size-preset list: 1..MaxOrderLevels entries, each a percentage in MinOrderLevel..MaxOrderLevel.

Types

type Config

type Config struct {
	// Keystore selects where NEWLY CREATED keys' private material goes: "file"
	// (default, encrypted file) or "keychain" (the OS keyring). It applies only
	// at key creation — every existing key carries its own backend in keys.json,
	// and changing this default never moves or re-routes an existing key (that
	// is `keystore migrate`'s job).
	Keystore string
	// BaseURL optionally overrides the REST base URL.
	BaseURL string
	// WSBaseURL optionally overrides the WebSocket base URL (scheme ws/wss),
	// used by the streaming `monitor` command. Empty means it is derived from
	// the resolved REST base URL.
	WSBaseURL string
	// TUIColorScheme is the persisted up/down color convention for the `tui`
	// command ("green-red" or "red-blue"), toggled with the C key and saved back
	// so it survives across launches. Stored under the "tui" object in
	// config.json. Empty means the TUI's default.
	TUIColorScheme string
	// TUIOrderLevels are the persisted %-of-balance size presets the `tui`
	// order UIs bind to number keys (e.g. [10,25,50,100], where 100 renders as
	// "max"). Stored under the "tui" object. Nil means unset — the tui command
	// pins the built-in defaults on first launch, so a later program update
	// never silently changes what a preset key does.
	TUIOrderLevels []int
}

Config is the resolved CLI configuration.

func Load

func Load(home string, log *slog.Logger) (Config, error)

Load reads config.json from home. A missing file yields the defaults (file backend, no base URL). Malformed config is a ConfigError. log (nil = silent) records the path, whether the file was present, and a parse failure — config.json holds no secrets, so it is safe to name the path.

Jump to

Keyboard shortcuts

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