Help us shape the future of Go! Take the 2026 Go Developer Survey

quadlet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package quadlet parses systemd unit files with Quadlet semantics.

The format is systemd's INI dialect, which differs from common INI in ways that matter here:

  • Keys may repeat within a section. `Volume=` appearing five times is five mounts, not one key overwritten four times, so the model is a list of entries rather than a map.
  • A line ending in a backslash continues onto the next line. Quadlet concatenates the trimmed fragments and skips comment and blank lines in between; see splitEntry.
  • Both `#` and `;` start a comment, but only at the beginning of a line. A `#` inside a value is part of the value.
  • The same section may appear more than once; systemd treats the second occurrence as a continuation of the first.

Parsing preserves enough of the original text to render it back byte for byte. The fix engine depends on that: rewriting one mount option must not reflow comments or reorder keys elsewhere in the file.

Reference: systemd.syntax(7) and podman-systemd.unit(5).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Section string
	Key     string
	Value   string
	Line    int
}

Entry is a single Key=value assignment together with the section it appeared in. Rules work in terms of entries.

type File

type File struct {
	// Path is where the file came from. Findings cite it.
	Path string
	// Lines is every logical line in order, including blanks and comments.
	Lines []Line
	// contains filtered or unexported fields
}

File is a parsed unit file that can be rendered back to its original bytes.

func Parse

func Parse(path string, r io.Reader) (*File, error)

Parse reads a unit file. It does not fail on unrecognised lines: a linter that refuses to parse is useless on exactly the malformed files a user most needs linted. Such lines are kept as LineUnknown for a rule to report.

func (*File) Entries

func (f *File) Entries() []Entry

Entries returns every assignment in file order.

func (*File) HasSection

func (f *File) HasSection(name string) bool

HasSection reports whether the named section appears at all, even empty. The distinction matters for `[Install]`: an empty one is still a statement of intent, whereas an absent one means the unit will never autostart.

func (*File) Lookup

func (f *File) Lookup(section, key string) (string, bool)

Lookup returns the last value of a key within a section. systemd's last-one-wins applies to keys that are not list-valued; for list-valued keys use Values.

func (*File) Render

func (f *File) Render() string

Render writes the file back out. For an unmodified file the result is byte-identical to the input; this is asserted by a round-trip test over every fixture.

func (*File) Section

func (f *File) Section(name string) []Entry

Section returns every entry in the named section, in file order. Section names are matched exactly: the generator ignores `[container]` in a `.container` file (verified against Podman 5.8.4).

func (*File) Values

func (f *File) Values(section, key string) []string

Values returns the values of every occurrence of a key within a section, in file order. Repeated keys are the norm in Quadlet, so this, not a lookup of one value, is the primary accessor. Keys are matched exactly, as systemd and Quadlet do.

type Line

type Line struct {
	Kind LineKind
	// Raw holds the original physical lines, without their terminators, so
	// the file can be rendered back exactly as it arrived.
	Raw []string
	// Number is the 1-based physical line number where this logical line
	// starts. Findings cite it.
	Number int

	// Section is set for LineSection: the name inside the brackets.
	Section string

	// Key and Value are set for LineEntry. Value is the logical value, with
	// continuations already joined; Raw retains how it was written.
	Key   string
	Value string
}

Line is one logical line of a unit file. A logical line spans several physical lines when continuations are used.

type LineKind

type LineKind int

LineKind classifies a physical line, so rendering can reproduce the original file without keeping a second copy of it.

const (
	// LineBlank is an empty or whitespace-only line.
	LineBlank LineKind = iota
	// LineComment is a line whose first non-space character is '#' or ';'.
	LineComment
	// LineSection is a `[Section]` header.
	LineSection
	// LineEntry is a `Key=value` assignment, possibly spanning continuations.
	LineEntry
	// LineUnknown is a line we could not classify. It is preserved verbatim
	// and reported, rather than being silently dropped.
	LineUnknown
)

Jump to

Keyboard shortcuts

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