docfile

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docfile reads the JSON and YAML documents the tool is configured by.

Both formats decode to the same shape -- JSON's value model -- so everything downstream (schema validation, strict struct decoding, the settings layers) handles one representation and cannot behave differently depending on which syntax a maintainer preferred.

Index

Constants

This section is empty.

Variables

View Source
var Extensions = []string{".json", ".yaml", ".yml"}

Extensions are tried in this order. JSON first, because every shipped config is JSON and a lookup should find it without a second stat.

Functions

func Find

func Find(dir, base string) (string, error)

Find returns dir/base with whichever supported extension exists.

Two at once is an error, not a preference order: a tabler.json beside a tabler.yaml means someone converted the file and forgot to delete the original, and silently picking one runs a config nobody is editing. Returns os.ErrNotExist (wrapped) when none exists.

base names a file in dir and nothing else: one that would leave dir (a `..`, an absolute path, a link out) is refused with pathguard.ErrEscape, because a pack slug from the web UI reaches here.

func IsYAML

func IsYAML(path string) bool

IsYAML reports whether a path names a YAML document.

func ParseTree added in v0.1.1

func ParseTree(path string, data []byte) (map[string]any, error)

ParseTree is ReadTree on bytes already in hand; path picks the format.

func ReadTree

func ReadTree(path string) (map[string]any, error)

ReadTree reads a document into a generic map. Numbers decode as float64, exactly as encoding/json produces them, whichever syntax the file used.

func ToJSON

func ToJSON(path string, data []byte) ([]byte, error)

ToJSON converts a document to canonical JSON bytes. JSON input is returned as-is after a validity check; YAML is decoded and re-encoded.

func WriteAtomic added in v0.1.1

func WriteAtomic(path string, data []byte) (err error)

WriteAtomic replaces path with data so that a reader sees either the old file or the new one, never a partial write.

The bytes go to a temporary file in the same directory (a rename is only atomic within one filesystem), are fsynced, take the existing file's permissions (0644 for a new file), and are renamed over the target. The directory is fsynced afterwards where the platform allows it, so the rename itself survives a crash. On any failure the temporary file is removed and the target is untouched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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