Skip to content

Commit

Permalink
use config.Load (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored Nov 16, 2023
1 parent 5e05cf6 commit 1ede0f6
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 207 deletions.
7 changes: 1 addition & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- Split file and fs provider (#49).
- Split Watch and OnChange for watching configuration changes (#52).

### Removed

- Remove konf.Logger in favor of slog (#48).
- [BREAKING] Redesign API.

## [v0.2.0] - 3/18/2023

Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ It defers the actual configuration loading to the `Loader` interface.
The `Loader` and `Watcher` interface is intended for configuration source library implementers.
They are pure interfaces which can be implemented to provide the actual configuration.

This decoupling allows application developers to write code in terms of `konf.Config`
This decoupling allows application developers to write code in terms of `*konf.Config`
while the configuration source(s) is managed "up stack" (e.g. in or near `main()`).
Application developers can then switch configuration sources(s) as necessary.

Expand All @@ -29,15 +29,14 @@ configuration source(s) (implementation) it actually wants to use. Something lik
var config embed.FS
func main() {
// Create the global Config that loads configuration
// from embed file system and environment variables.
config, err := konf.New(
konf.WithLoader(
fs.New(config, "config/config.json"),
env.New(env.WithPrefix("server")),
),
)
if err != nil {
// Create the Config.
config := konf.New()
// Load configuration from embed file system and environment variables.
if err := config.Load(
fs.New(config, "config/config.json"),
env.New(env.WithPrefix("server")),
); err != nil {
// Handle error here.
}
Expand Down
11 changes: 7 additions & 4 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (

func BenchmarkNew(b *testing.B) {
var (
config konf.Config
config *konf.Config
err error
)
for i := 0; i < b.N; i++ {
config, err = konf.New(konf.WithLoader(mapLoader{"k": "v"}))
config = konf.New()
err = config.Load(mapLoader{"k": "v"})
}
b.StopTimer()

Expand All @@ -26,7 +27,8 @@ func BenchmarkNew(b *testing.B) {
}

func BenchmarkGet(b *testing.B) {
config, err := konf.New(konf.WithLoader(mapLoader{"k": "v"}))
config := konf.New()
err := config.Load(mapLoader{"k": "v"})
assert.NoError(b, err)
konf.SetGlobal(config)
b.ResetTimer()
Expand All @@ -41,7 +43,8 @@ func BenchmarkGet(b *testing.B) {
}

func BenchmarkUnmarshal(b *testing.B) {
config, err := konf.New(konf.WithLoader(mapLoader{"k": "v"}))
config := konf.New()
err := config.Load(mapLoader{"k": "v"})
assert.NoError(b, err)
konf.SetGlobal(config)
b.ResetTimer()
Expand Down
Loading

0 comments on commit 1ede0f6

Please sign in to comment.