Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![codecov](https://codecov.io/gh/Insei/tinyconf/graph/badge.svg?token=TSOJ1SWF9D)](https://codecov.io/gh/Insei/tinyconf)
[![build](https://github.com/insei/tinyconf/actions/workflows/go.yml/badge.svg)](https://github.com/Insei/tinyconf/actions/workflows/go.yml)
[![Goreport](https://goreportcard.com/badge/github.com/insei/tinyconf)](https://goreportcard.com/report/github.com/insei/tinyconf)
[![GoDoc](https://godoc.org/github.com/insei/tinyconf?status.svg)](https://godoc.org/github.com/insei/tinyconf)
[![GoDoc](https://godoc.org/github.com/insei/tinyconf/v2?status.svg)](https://godoc.org/github.com/insei/tinyconf/v2)
# tinyconf
tinyconf - a simple and universal library for parsing configs.

Expand All @@ -10,8 +10,9 @@ Documentation: [insei.github.io/tinyconf](https://insei.github.io/tinyconf/) —
# Installation
Install via go get. Note that Go 1.19 or newer is required.
```sh
go get github.com/insei/tinyconf@latest
go get github.com/insei/tinyconf/v2@latest
```
Upgrading from v1: see [Upgrading to v2](https://insei.github.io/tinyconf/latest/upgrading/).

# Description
tinyconf fills config structs with values from drivers. When initializing `tinyconf.Manager`, you can add a logger to it,
Expand Down Expand Up @@ -190,12 +191,12 @@ import (
"fmt"
"time"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/env"
"github.com/insei/tinyconf/drivers/flag"
"github.com/insei/tinyconf/drivers/tag"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/logger"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/env"
"github.com/insei/tinyconf/v2/drivers/flag"
"github.com/insei/tinyconf/v2/drivers/tag"
"github.com/insei/tinyconf/v2/drivers/yaml"
"github.com/insei/tinyconf/v2/logger"
)

type HTTP struct {
Expand Down Expand Up @@ -305,4 +306,4 @@ If the driver implements the optional `tinyconf.Loader` or `tinyconf.ContextLoad
so the driver can read its source once and not for every field.
If the driver implements the optional `tinyconf.Watcher` interface, it can report changes of its source for reloading.

More examples: the service in the [`example`](example) directory, runnable examples on [pkg.go.dev](https://pkg.go.dev/github.com/insei/tinyconf#pkg-examples), recipes in the [documentation](https://insei.github.io/tinyconf/latest/use-cases/).
More examples: the service in the [`example`](example) directory, runnable examples on [pkg.go.dev](https://pkg.go.dev/github.com/insei/tinyconf/v2#pkg-examples), recipes in the [documentation](https://insei.github.io/tinyconf/latest/use-cases/).
6 changes: 3 additions & 3 deletions cmp118/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ package cmp118
// See the [Compare] function for a consistent way to compare NaN values.
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 |
~string
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 |
~string
}

// Compare returns
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/consul.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Both ways report changes for [reloading](../features/reloading.md) as soon as th
## Key per field

```go
import "github.com/insei/tinyconf/drivers/consul"
import "github.com/insei/tinyconf/v2/drivers/consul"

consulDriver, err := consul.New("app")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The env driver reads values from environment variables and `.env` files.

```go
import "github.com/insei/tinyconf/drivers/env"
import "github.com/insei/tinyconf/v2/drivers/env"

envDriver, err := env.New()
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/etcd.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Both ways report changes for [reloading](../features/reloading.md) as soon as th
## Key per field

```go
import "github.com/insei/tinyconf/drivers/etcd"
import "github.com/insei/tinyconf/v2/drivers/etcd"

etcdDriver, err := etcd.New("app")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/flag.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The flag driver reads values from command line flags.

```go
import "github.com/insei/tinyconf/drivers/flag"
import "github.com/insei/tinyconf/v2/drivers/flag"

flagDriver, err := flag.New()
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The format driver reads config files of any format with nested objects. The format is set by a function that decodes the content to a map, everything else is the same as in the [yaml](yaml.md), [json](json.md) and [toml](toml.md) drivers: several files, merging, embedded files, [remote documents](consul.md#document), environment variables in the content, [reloading](../features/reloading.md), [documentation](../features/gendoc.md).

```go
import "github.com/insei/tinyconf/drivers/format"
import "github.com/insei/tinyconf/v2/drivers/format"

driver, err := format.New("hujson", decodeHuJSON, "config.hujson")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/ini.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The ini driver reads values from INI files.

```go
import "github.com/insei/tinyconf/drivers/ini"
import "github.com/insei/tinyconf/v2/drivers/ini"

iniDriver, err := ini.New("config.ini")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The json driver reads values from JSON files.

```go
import "github.com/insei/tinyconf/drivers/json"
import "github.com/insei/tinyconf/v2/drivers/json"

jsonDriver, err := json.New("config.json")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The properties driver reads values from `.properties` files — the format of Java and Spring, `application.properties`.

```go
import "github.com/insei/tinyconf/drivers/properties"
import "github.com/insei/tinyconf/v2/drivers/properties"

propertiesDriver, err := properties.New("application.properties")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The tag driver takes values right from the struct tags. It is used for default values.

```go
import "github.com/insei/tinyconf/drivers/tag"
import "github.com/insei/tinyconf/v2/drivers/tag"

tagDriver, err := tag.New("initial")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The toml driver reads values from TOML files.

```go
import "github.com/insei/tinyconf/drivers/toml"
import "github.com/insei/tinyconf/v2/drivers/toml"

tomlDriver, err := toml.New("config.toml")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/vault.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The vault driver reads values from the [KV secrets engine](https://developer.hashicorp.com/vault/docs/secrets/kv) of HashiCorp Vault.

```go
import "github.com/insei/tinyconf/drivers/vault"
import "github.com/insei/tinyconf/v2/drivers/vault"

vaultDriver, err := vault.New("app/config")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers/yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The yaml driver reads values from YAML files.

```go
import "github.com/insei/tinyconf/drivers/yaml"
import "github.com/insei/tinyconf/v2/drivers/yaml"

yamlDriver, err := yaml.New("config.yaml")
```
Expand Down
2 changes: 1 addition & 1 deletion docs/features/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Add the tag to the parent, `yaml:"http"`, to read the value from `http.host`.
## Bundled loggers

```go
import "github.com/insei/tinyconf/logger"
import "github.com/insei/tinyconf/v2/logger"

// prints to stdout, levels: FATAL, ERROR, WARN, INFO, DEBUG, TRACE
tinyconf.WithLogger(logger.NewFmtLogger(logger.INFO))
Expand Down
14 changes: 7 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Install

```bash
go get github.com/insei/tinyconf@latest
go get github.com/insei/tinyconf/v2@latest
```

Minimum Go version is **1.19**.
Expand All @@ -22,11 +22,11 @@ import (
"fmt"
"time"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/env"
"github.com/insei/tinyconf/drivers/tag"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/logger"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/env"
"github.com/insei/tinyconf/v2/drivers/tag"
"github.com/insei/tinyconf/v2/drivers/yaml"
"github.com/insei/tinyconf/v2/logger"
)

type HTTP struct {
Expand Down Expand Up @@ -114,7 +114,7 @@ and `HTTP_HOST=example.com` in the environment the program prints

Bundled drivers and how to write your own.

- :simple-go:{ .lg } **[API reference →](https://pkg.go.dev/github.com/insei/tinyconf)**
- :simple-go:{ .lg } **[API reference →](https://pkg.go.dev/github.com/insei/tinyconf/v2)**

Autogenerated on pkg.go.dev.

Expand Down
15 changes: 15 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Upgrading to v2

v2 changes the module path and a few methods. The steps for the code of v1:

1. Change the imports from `github.com/insei/tinyconf/...` to `github.com/insei/tinyconf/v2/...`:

```sh
go get github.com/insei/tinyconf/v2@latest
```

2. `Parse` takes the context: `Parse(conf)` is `Parse(context.Background(), conf)`. The context stops the requests of the [remote drivers](features/manager.md#parse).

3. The zap adapter is the separate module, zap is not a dependency of the core anymore: `logger.NewZapLogger(l)` is `zaplogger.New(l)` from `github.com/insei/tinyconf/logger/zaplogger`, see [Logging](features/logging.md).

4. Fields of an [embedded struct](features/structs.md#embedded-structs) without the tag are on the level of the embedding struct, like in `encoding/json`. Check the keys of such fields in the files and the environment variables.
4 changes: 3 additions & 1 deletion docs/why-tinyconf.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ Checked against the current documentation of the libraries on 2026-10-16.
- **No HCL out of the box.** The [format driver](drivers/format.md) accepts any decoder, but the conversion of HCL to a map is up to you.
- **Own flag parser.** It ignores unknown flags, so it lives next to cobra or any CLI framework, but it is not a pflag integration.
- **Subscriptions are package functions,** `tinyconf.Subscribe(ctx, config, ...)`, to keep Go 1.19 support; methods with type parameters need Go 1.27.
- **zap is a dependency of the core** because of the bundled logger adapter, even if you use another logger.
- **A younger and smaller project** than viper and koanf.

## Migrating

From tinyconf v1: see [Upgrading to v2](upgrading.md).


| From | To tinyconf |
|---|---|
| viper `SetDefault("http.port", 8080)` | `initial:"8080"` with the [tag driver](drivers/tag.md) |
Expand Down
8 changes: 4 additions & 4 deletions drivers/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"testing"
"time"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/env"
"github.com/insei/tinyconf/drivers/tag"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/env"
"github.com/insei/tinyconf/v2/drivers/tag"
"github.com/insei/tinyconf/v2/drivers/yaml"
)

type benchServer struct {
Expand Down
16 changes: 8 additions & 8 deletions drivers/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"github.com/stretchr/testify/assert"
yamlv3 "gopkg.in/yaml.v3"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/convert"
"github.com/insei/tinyconf/drivers/env"
"github.com/insei/tinyconf/drivers/flag"
jsondriver "github.com/insei/tinyconf/drivers/json"
"github.com/insei/tinyconf/drivers/tag"
tomldriver "github.com/insei/tinyconf/drivers/toml"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/convert"
"github.com/insei/tinyconf/v2/drivers/env"
"github.com/insei/tinyconf/v2/drivers/flag"
jsondriver "github.com/insei/tinyconf/v2/drivers/json"
"github.com/insei/tinyconf/v2/drivers/tag"
tomldriver "github.com/insei/tinyconf/v2/drivers/toml"
"github.com/insei/tinyconf/v2/drivers/yaml"
)

type conformanceNamedString string
Expand Down
2 changes: 1 addition & 1 deletion drivers/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"time"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/v2"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions drivers/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

"github.com/insei/fmap/v3"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/convert"
"github.com/insei/tinyconf/drivers/internal/tree"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/convert"
"github.com/insei/tinyconf/v2/drivers/internal/tree"
)

const name = "consul"
Expand Down
4 changes: 2 additions & 2 deletions drivers/consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/insei/fmap/v3"
"github.com/stretchr/testify/assert"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/yaml"
)

func init() {
Expand Down
10 changes: 5 additions & 5 deletions drivers/embedded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

"github.com/stretchr/testify/assert"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/env"
"github.com/insei/tinyconf/drivers/json"
"github.com/insei/tinyconf/drivers/toml"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/env"
"github.com/insei/tinyconf/v2/drivers/json"
"github.com/insei/tinyconf/v2/drivers/toml"
"github.com/insei/tinyconf/v2/drivers/yaml"
)

type embeddedCommon struct {
Expand Down
8 changes: 4 additions & 4 deletions drivers/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"strings"
"unicode"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/cmp118"
"github.com/insei/tinyconf/convert"
"github.com/insei/tinyconf/slices118"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/cmp118"
"github.com/insei/tinyconf/v2/convert"
"github.com/insei/tinyconf/v2/slices118"

"github.com/insei/fmap/v3"
)
Expand Down
2 changes: 1 addition & 1 deletion drivers/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/insei/fmap/v3"
"github.com/insei/tinyconf"
"github.com/insei/tinyconf/v2"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions drivers/env/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"os"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/env"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/env"
)

// With the prefix, auto keys and indexed keys the variables are found without the env tags of every field.
Expand Down
2 changes: 1 addition & 1 deletion drivers/etcd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sync"
"time"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/v2"
)

// DefaultEndpoint is used if the endpoints are not set by the option and by the ETCDCTL_ENDPOINTS variable.
Expand Down
6 changes: 3 additions & 3 deletions drivers/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

"github.com/insei/fmap/v3"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/convert"
"github.com/insei/tinyconf/drivers/internal/tree"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/convert"
"github.com/insei/tinyconf/v2/drivers/internal/tree"
)

const name = "etcd"
Expand Down
4 changes: 2 additions & 2 deletions drivers/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/insei/fmap/v3"
"github.com/stretchr/testify/assert"

"github.com/insei/tinyconf"
"github.com/insei/tinyconf/drivers/yaml"
"github.com/insei/tinyconf/v2"
"github.com/insei/tinyconf/v2/drivers/yaml"
)

func init() {
Expand Down
Loading
Loading