Read Java properties¶
The core reads and writes only YAML. Java .properties come from a sibling module,
config-properties, which adds
nothing to your dependency graph — 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:
host := store.View().GetString("server.host") // "localhost"
port := store.View().GetInt("server.port") // 8080
A properties layer therefore 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 in the module states it. No filesystem library: you supply the
config.FS.
Related¶
- Support a new file format — how an adapter like this is built and tested
- Read dotenv and Read INI — the other flat formats