tinyConf
tinyConf is a lightweight Go library for reading plain text key=value configuration files.
It is designed for small, simple configurations where complex formats like YAML/TOML/JSON are unnecessary.
The library is deterministic, minimal, and easy to reason about.
Lines starting with # or ; are treated as comments.
Empty lines are ignored.
Features
- Plain
key=value configuration format
- Generic access via
Get[T]
- Built-in support for:
string
int
bool
time.Duration
- Support for custom types via converters
- Safe defaults on missing keys or conversion errors
- Required keys validation
- Reload config from disk
- List all keys
- Dump config for debugging
- No struct tags
- No reflection-based magic
- No external dependencies
Installation
go get github.com/lnkssr/tinyConf
# Example config
; comment variant
work_dir = /var/lib/videos
index_file = ./index.html
max_items = 50
debug = true
timeout = 30s
start_point = 100,200
Usage
package main
import (
"errors"
"fmt"
"log"
"strconv"
"strings"
"time"
"github.com/lnkssr/tinyConf"
)
func main() {
cfg, err := tinyConf.Load("config")
if err != nil {
log.Fatal(err)
}
videoDir := tinyConf.Get(cfg, "work_dir", "/tmp/videos")
indexFile := tinyConf.Get(cfg, "index_file", "./index.html")
maxItems := tinyConf.Get(cfg, "max_items", 10)
debugMode := tinyConf.Get(cfg, "debug", false)
timeout := tinyConf.Get(cfg, "timeout", 5*time.Second)
fmt.Println(videoDir, indexFile, maxItems, debugMode, timeout)
}
Required Keys
port, err := tinyConf.Require[int](cfg, "port")
if err != nil {
log.Fatal(err)
}
Require[T] returns an error if:
- the key is missing
- the value cannot be converted
Custom Types
type Point struct{ X, Y int }
pointConverter := func(s string) (Point, error) {
parts := strings.Split(s, ",")
if len(parts) != 2 {
return Point{}, errors.New("invalid format")
}
x, err := strconv.Atoi(parts[0])
if err != nil {
return Point{}, err
}
y, err := strconv.Atoi(parts[1])
if err != nil {
return Point{}, err
}
return Point{X: x, Y: y}, nil
}
start := tinyConf.Get(cfg, "start_point", Point{X: 0, Y: 0}, pointConverter)
Reload Configuration
err := cfg.Reload()
if err != nil {
log.Fatal(err)
}
Reload rereads the config file from disk and atomically replaces values.
Debugging
cfg.Dump()
Prints all key=value pairs to stdout.
Intended for debugging only.
API
Load(path string) (*Config, error)
Loads a config file into memory.
Get[T](cfg *Config, key string, def T, converter ...Converter[T]) T
Returns a value of type T.
- Returns
def if key is missing
- Returns
def if conversion fails
- Optional converter enables custom types
Require[T](cfg *Config, key string, converter ...Converter[T]) (T, error)
Returns a value of type T or an error if the key is missing or invalid.
Reload() error
Reloads the configuration file from disk.
Keys() []string
Returns all configuration keys.
Dump()
Prints all config values for debugging.
Design Philosophy
- Small configs only
- No nested structures
- No environment variable injection
- No implicit behavior
- Explicit is better than clever
- Easy to remove or replace
If you need advanced features - use TOML, YAML, or JSON.
If you need a simple config - use tinyConf.
License
MIT