config

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPathNotFound = errors.New("config: path not found")

ErrPathNotFound reports that a requested JSONC path did not exist.

Functions

func DeleteAPIConfig

func DeleteAPIConfig(path, apiName string) error

DeleteAPIConfig removes a single API entry from the JSONC config file while preserving surrounding comments and formatting when possible.

func NeedsPatchToPreserveFormatting

func NeedsPatchToPreserveFormatting(path string) bool

NeedsPatchToPreserveFormatting reports whether the config file at path contains JSONC comments and should use patch-based writes to preserve formatting. Returns false when the file does not exist or cannot be read.

func PatchConfigShorthandBytes

func PatchConfigShorthandBytes(data []byte, rootPath []string, exprs []string) ([]byte, *config.Config, error)

PatchConfigShorthandBytes applies shorthand patch expressions to JSONC config bytes and returns the patched bytes plus the decoded typed config.

func ReadAll added in v2.3.0

func ReadAll(folder string) (map[string]*config.APIConfig, error)

ReadAll returns every API defined in folder, in v2 shape. Tries restish.json first, then apis.json, converting legacy entries.

func ReadProfile added in v2.3.0

func ReadProfile(folder, apiName string) (*config.APIConfig, error)

ReadProfile loads the named API from folder, returning its v2-shaped *config.APIConfig. It tries restish.json (v2) first and falls back to apis.json (v1), converting legacy entries on the fly.

func SaveAPIConfig

func SaveAPIConfig(path, apiName string, apiCfg *config.APIConfig) error

SaveAPIConfig updates a single API entry in the JSONC config file while preserving surrounding comments and formatting when possible.

func SaveConfigMutation

func SaveConfigMutation(path string, mutate func(*config.Config) error, validate func(*config.Config) error) error

SaveConfigMutation applies a typed config mutation atomically under the config file lock while preserving JSONC comments and formatting where possible.

func SaveConfigShorthand

func SaveConfigShorthand(path string, rootPath []string, exprs []string, validate func(*config.Config) error) error

SaveConfigShorthand applies shorthand patch expressions to the JSONC config file under rootPath, validates the final config, and writes it atomically while preserving comments where possible.

func SaveConfigValue

func SaveConfigValue(path string, objectPath []string, value any) error

SaveConfigValue updates a single object path inside the JSONC config file while preserving surrounding comments and formatting when possible.

func SaveConfigValues

func SaveConfigValues(path string, ops []ConfigPatchOperation) error

SaveConfigValues applies multiple config edits atomically under one file lock, preserving JSONC comments and formatting where possible.

func TryMigrate added in v2.3.0

func TryMigrate(path string) (*config.MigrationInfo, error)

TryMigrate inspects the user's config directory for a legacy v1 config (apis.json / config.json) and migrates it to a v2 restish.json at path. Returns (nil, nil) when no legacy source is present. The restish CLI calls this explicitly before config.Load; embedders using config.Load do not see a migration triggered automatically.

func ValidateShape

func ValidateShape(value any) error

ValidateShape validates generic decoded config data against the config.Config schema generated from Go structs.

Types

type ConfigPatchOperation

type ConfigPatchOperation struct {
	Path   []string
	Value  any
	Delete bool
}

ConfigPatchOperation describes one config edit operation. If Delete is true, Value is ignored and Path is removed.

type ConfigShapeError

type ConfigShapeError struct {
	Errors []error
}

ConfigShapeError reports one or more structural validation failures.

func (*ConfigShapeError) Error

func (e *ConfigShapeError) Error() string

Jump to

Keyboard shortcuts

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