Documentation
¶
Overview ¶
Package configfile reads and edits the settings files emulators keep, in their own formats: INI, TOML, YAML, XML and JSON. An edit changes only the value it names and leaves the rest of the file as the emulator wrote it, so a person's own changes, comments and keys this package knows nothing about survive.
The files live in a folder the emulator can write to, and an emulator is treated as something that may have been taken over, so every reader here expects hostile input: it refuses files over MaxSize, never panics, and a value can never add a line, a section or an element of its own.
Index ¶
Constants ¶
const MaxSize = 4 << 20
MaxSize is the largest file this reads or edits. An emulator's own is a few kilobytes.
Variables ¶
var Formats = []string{"ini", "toml", "yaml", "xml", "json"}
Formats this package knows.
Functions ¶
func Apply ¶
Apply makes edits to a file's text and returns the new text. old may be empty: the file is then made. Paths are, by format:
- ini: [section, key]
- toml: [table..., key], dotted tables as their parts
- yaml: [key, key, ...] through nested block maps
- xml: [element, element, ...] from the root element down to the one whose text is set
- json: [key, ...] through nested objects
A value that would end up somewhere it can't be written plainly (in a TOML array, under a YAML key that holds a list, in an XML element with children of its own) is refused rather than guessed at.
Types ¶
type Edit ¶
Edit sets one value. Path names it in the file's own terms (see Apply); Value is a bool, an int64, a float64 or a string. In JSON it may also be a []any or a map[string]any of those (and of each other), which replaces whatever the file had there, list or object, whole.