configproperties

package module
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 5 Imported by: 0

README

config-properties

Read Java .properties 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 reads and writes only YAML. Every other file format is a sibling module like this one — and this one adds nothing to your dependency graph, because a .properties file is read with the standard library.

import (
	"gitlab.com/phpboyscout/go/config"
	configproperties "gitlab.com/phpboyscout/go/config-properties"
)

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

Keys nest on dots

A properties key is dotted already, and each dot is a nesting separator:

server.host=localhost
server.port=8080

reads as server.host and server.port, so a properties layer merges into a nested YAML or JSON one by the same paths. In Java a dotted key is a single flat string; here it nests, which is what makes it a configuration layer rather than a map.

The format it honours

key=value, key:value and key value are all separators; leading whitespace and whitespace around the separator is ignored; # and ! begin a comment; a line ending in an odd number of backslashes continues onto the next; and the standard escapes are recognised in keys and values — \t \n \r \f \\, an escaped separator or space, and \uXXXX.

Read-only

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

What it costs

Only the config graph — a .properties 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 configproperties reads Java `.properties` configuration through the config codec seam.

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

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

Keys nest on dots

A properties key is dotted already, and each dot is a nesting separator, so `server.host=localhost` reads as server.host and merges into a nested YAML or JSON layer by the same path. In Java a dotted key is a single flat string; here it nests, which is what makes it a configuration layer rather than a map.

The format it honours

`key=value`, `key:value` and `key value` are all separators; leading whitespace and whitespace around the separator is ignored; `#` and `!` begin a comment; a line ending in an odd number of backslashes continues onto the next; and the standard escapes are recognised in keys and values — `\t \n \r \f \\`, an escaped separator or space, and `\uXXXX`. 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 a Java properties document.

Types

type Codec added in v0.2.0

type Codec struct{}

Codec decodes key=value properties 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 a properties 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