Documentation
¶
Overview ¶
Package utils ...
Index ¶
- func AtomicWriteYAML(fs afero.Fs, path string, v any, mode os.FileMode) error
- func ExpandHome(path string) (string, error)
- func RedactDSNKeyValues(s string) string
- func ResolveTemplate(tmpl string, data any) (string, error)
- func ScanLinesAndTruncateWhenLongerThanBuffer(data []byte, atEOF bool) (advance int, token []byte, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteYAML ¶
AtomicWriteYAML marshals v as YAML and atomically replaces path on POSIX file systems. It exclusively creates a temporary file in the destination directory with the supplied mode, closes it, then renames it onto path. On failure only that writer's temporary file is removed best-effort.
The parent directory of path is created with mode 0700 if it does not already exist. AtomicWriteYAML does NOT chmod an existing parent dir.
Concurrent saves publish complete snapshots; they do not merge updates.
func ExpandHome ¶
ExpandHome resolves a leading "~" to the user's home directory. A bare "~" or "~/..." is expanded; any other path is returned unchanged. A missing HOME (os.UserHomeDir error) yields a wrapped error rather than a panic.
func RedactDSNKeyValues ¶ added in v0.10.1
RedactDSNKeyValues scrubs password and sslpassword assignments embedded in connection strings or error text. Backslashes escape the next byte in both quoted and bare values. Unterminated quoted values consume the remainder so an uncertain boundary cannot expose a password suffix.
func ResolveTemplate ¶
ResolveTemplate executes a text/template against data and returns the result. Caller is responsible for trust boundaries of both 'tmpl' and 'data'. The rendered output MUST NOT be passed unescaped to a shell, SQL driver, or any other interpreter without context-appropriate escaping. text/template provides no command-injection protection. See also: html/template for HTML contexts.
ResolveTemplate never panics: any template parse or execute error is returned as ("", err).
func ScanLinesAndTruncateWhenLongerThanBuffer ¶
func ScanLinesAndTruncateWhenLongerThanBuffer(data []byte, atEOF bool) (advance int, token []byte, err error)
ScanLinesAndTruncateWhenLongerThanBuffer is a bufio.SplitFunc that behaves like bufio.ScanLines but silently truncates any single line longer than constants.MaxLineLength (1 MiB). It is intended for non-UI scan paths where dropping bytes is preferable to bufio.ErrTooLong; UI paths should render their own truncation marker (deferred to E5+).
Types ¶
This section is empty.