config

package
v3.3.1 Latest Latest
Warning

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

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

Documentation

Overview

Package config reads and writes the configuration file of the CLI, config.json in the configuration folder. The file holds no secret.

Index

Constants

View Source
const (
	DefaultInstance = "mai"
	DefaultPort     = 8765
	ImageRepository = "ghcr.io/monorithm/mai"
)

Default values of the fields.

View Source
const FileName = "config.json"

FileName is the name of the configuration file in the configuration folder.

Variables

This section is empty.

Functions

func DefaultImage

func DefaultImage() string

DefaultImage is the image of the version of the CLI.

func Path

func Path(dir string) string

Path returns the location of config.json in the configuration folder dir.

func PinImage

func PinImage(dir, image string) error

PinImage writes the image field of the file. An empty image removes the pin, so that the CLI uses the image of its version.

func Save

func Save(dir string, c Config) error

Save writes c to config.json in the configuration folder dir, with mode 0600.

func Update

func Update(dir string, o Overrides) error

Update applies o to the fields of the file in dir and writes the file. A field that the file does not hold stays out of the file, so that its default can change with the CLI. When o names a different instance, the port, the image, and the data folder of the file are of the instance before it. Thus these fields go, and only the values of o stay.

Types

type Config

type Config struct {
	Instance string `json:"instance"`
	Port     int    `json:"port"`
	Image    string `json:"image"`
	DataDir  string `json:"data_dir"`
}

Config is the content of config.json.

func Defaults

func Defaults() Config

Defaults returns a Config with the default value in each field.

func Load

func Load(dir string) (Config, error)

Load reads config.json from the configuration folder dir. A missing file or a missing field gives the default value.

func (Config) Apply

func (c Config) Apply(o Overrides) Config

Apply returns c with each value of o that is set.

type Overrides

type Overrides struct {
	Instance string
	Port     int
	Image    string
	DataDir  string
}

Overrides are the values of command flags. An empty field keeps the value of the file.

Jump to

Keyboard shortcuts

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