configini

package module
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 4 Imported by: 0

README

config-ini

Read INI configuration through config — with no added dependency

Go Reference Pipeline Coverage phpboyscout Go toolkit

Part of the phpboyscout Go toolkit — small, framework-free Go modules extracted from go-tool-base. Documented with the parent module at config.go.phpboyscout.uk


config has one codec of its own, YAML, which also reads JSON because YAML 1.2 is a superset of it. Every other file format is a sibling module like this one — and this one adds nothing to your dependency graph, because an INI file is read with the standard library.

import (
	"gitlab.com/phpboyscout/go/config"
	configini "gitlab.com/phpboyscout/go/config-ini"
)

store, err := config.NewStore(ctx,
	config.WithFiles(fsys, "/etc/app.yaml"),                  // YAML, the default
	config.WithBackend(configini.New(fsys, "/etc/app.ini")),  // outranks it
)

Sections and keys nest on dots

A [section] header prefixes the keys beneath it:

[server]
host = localhost
port = 8080

reads as server.host and server.port, so an INI layer merges into a nested YAML or JSON one by the same paths. A section name or a key may itself contain dots, and each is a nesting separator — [db.primary] with pool.size = 4 reads as db.primary.pool.size. Keys before any section are top-level. A line is key = value or key : value; ; and # begin a comment; and surrounding single or double quotes are stripped from a value.

Read-only

Values are strings; the read path casts. The format is read-only.

What it costs

Only the config graph — an INI file is parsed with the standard library, so there is no parser module. An allowlist test states it. No filesystem library: you supply the config.FS.

License

See LICENSE.

Documentation

Overview

Package configini reads INI configuration through the config codec seam.

It is a sibling of the config core, not part of it, and adds no dependency at all — an INI file is read with the standard library.

config.NewStore(ctx,
	config.WithFiles(fsys, "/etc/app.yaml"),        // YAML, the default
	config.WithBackend(configini.New(fsys, "/etc/app.ini")),
)

Sections and keys nest on dots

A `[section]` header prefixes the keys beneath it, so

[server]
host = localhost

reads as server.host. Both a section name and a key may themselves contain dots, and each dot is a nesting separator: `[db.primary]` with `pool.size = 4` reads as db.primary.pool.size. Keys before any section are top-level.

A line is `key = value` or `key : value`; `;` and `#` begin a comment; surrounding single or double quotes are stripped from a value. The format is read-only, and values are strings that the read path casts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(filesystem config.FS, path string) config.Backend

New reads an INI document.

Types

type Codec added in v0.2.0

type Codec struct{}

Codec decodes INI sections and keys into layer values. New uses it, and it is exported so a backend adapter can reuse it as a value decoder — a key whose value is an INI document, decoded via that adapter's WithValueCodec option. It is a config.Codec.

func (Codec) Decode added in v0.2.0

func (Codec) Decode(path string, src []byte) ([]map[string]any, error)

Jump to

Keyboard shortcuts

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