Documentation
¶
Index ¶
- Variables
- func DeleteAPIConfig(path, apiName string) error
- func NeedsPatchToPreserveFormatting(path string) bool
- func PatchConfigShorthandBytes(data []byte, rootPath []string, exprs []string) ([]byte, *config.Config, error)
- func ReadAll(folder string) (map[string]*config.APIConfig, error)
- func ReadProfile(folder, apiName string) (*config.APIConfig, error)
- func SaveAPIConfig(path, apiName string, apiCfg *config.APIConfig) error
- func SaveConfigMutation(path string, mutate func(*config.Config) error, ...) error
- func SaveConfigShorthand(path string, rootPath []string, exprs []string, ...) error
- func SaveConfigValue(path string, objectPath []string, value any) error
- func SaveConfigValues(path string, ops []ConfigPatchOperation) error
- func TryMigrate(path string) (*config.MigrationInfo, error)
- func ValidateShape(value any) error
- type ConfigPatchOperation
- type ConfigShapeError
Constants ¶
This section is empty.
Variables ¶
var ErrPathNotFound = errors.New("config: path not found")
ErrPathNotFound reports that a requested JSONC path did not exist.
Functions ¶
func DeleteAPIConfig ¶
DeleteAPIConfig removes a single API entry from the JSONC config file while preserving surrounding comments and formatting when possible.
func NeedsPatchToPreserveFormatting ¶
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
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
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 ¶
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 ¶
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 ¶
ValidateShape validates generic decoded config data against the config.Config schema generated from Go structs.
Types ¶
type ConfigPatchOperation ¶
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