ini

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ini is the "encoding/ini" host module. See std/encoding/register.go for why this and its eight siblings each get their own leaf package instead of living in std's flat root, and how this directory's Module reaches the rest of magus without std importing back down to collect it.

Index

Constants

This section is empty.

Variables

View Source
var Module = std.Module{
	Name: "ini",
	WASM: true,
	Path: "encoding/ini",
	Doc:  "INI/properties config parsing and rendering (.npmrc, .gitconfig, .editorconfig).",
	Methods: []std.Method{
		{
			Name:    "parse",
			Doc:     "Parse INI text into {section: {key: value}}. Entries before the first [section] header are under the \"\" key, which is where a flat file like .npmrc puts everything. Values are always strings; a repeated key takes the last value.",
			Args:    []std.Arg{{Name: "source", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeStringMapMap}},
			Raises:  true,
			Impl:    INIParse,
		},
		{
			Name:    "stringify",
			Doc:     "Render {section: {key: value}} back to INI text. The \"\" section is written first with no header, then the rest sorted by name with their keys sorted, so the output is byte-stable and diffs cleanly.",
			Args:    []std.Arg{{Name: "sections", Type: std.TypeStringMapMap}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Impl:    INIStringify,
		},
	},
}

Module is the "encoding/ini" host module: the key=value config format that has no standard and is everywhere anyway - .npmrc, .gitconfig, .editorconfig, setup.cfg, .flake8, most systemd units.

tools/audit.buzz is the reason this exists. It carries a `coolingHours` constant with the comment "mirrors minimum-release-age in each project's .npmrc ... restated as a duration because .npmrc is not a format Buzz reads" - a value duplicated by hand, in a second unit, that can drift from the file it mirrors. That is what a missing parser costs.

WHAT THIS PARSES, stated plainly because INI has no specification and every implementation draws the line somewhere different:

  • `[section]` headers; entries before the first are under the "" key.
  • `key = value` and `key=value`; surrounding whitespace is trimmed from both.
  • `;` and `#` comment lines. A `#` INSIDE a value is kept, because a value is frequently a URL with a fragment and treating that as a comment silently truncates it.
  • Quoted values ("..." or '...') have their quotes stripped, which is how a value with meaningful leading or trailing spaces is written.
  • A repeated key takes the LAST value, matching how git and npm resolve one.

What it deliberately does NOT do: subsections (`[a "b"]` is one section named literally `a "b"`), multi-line continuations, or type inference. Every value is a string; a caller that wants a number parses it, which is the honest shape when the format itself has no types.

Functions

func INIParse

func INIParse(_ context.Context, source string) (map[string]map[string]string, error)

INIParse parses INI text into a section -> key -> value map.

func INIStringify

func INIStringify(_ context.Context, sections map[string]map[string]string) (string, error)

INIStringify renders a section -> key -> value map back to INI text.

func Modules

func Modules() []std.Module

Modules returns this directory's contribution to the encoding module set. See std/encoding/register.go: it aggregates every leaf's Modules() into one slice, which is how a module here reaches std.All()'s callers without std importing this package to collect it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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