Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#152): migrate toml package #153

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions aconfigtoml/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/cristalhq/aconfig/aconfigtoml

go 1.16
go 1.21.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this bump?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generated automatically.
The pelletier/go-toml declare the golang version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you know the underlying reason of BurntSushi/toml, we won't need to exchange it.


toolchain go1.23.0

require (
github.com/BurntSushi/toml v1.1.0
github.com/cristalhq/aconfig v0.17.0
github.com/cristalhq/aconfig v0.18.5
github.com/pelletier/go-toml/v2 v2.2.3
)
16 changes: 12 additions & 4 deletions aconfigtoml/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cristalhq/aconfig v0.17.0 h1:VYqg0YOM5yUEx0KH/VwUYF2e/PNI7dcUE66y+xEx73s=
github.com/cristalhq/aconfig v0.17.0/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig v0.18.5 h1:QqXH/Gy2c4QUQJTV2BN8UAuL/rqZ3IwhvxeC8OgzquA=
github.com/cristalhq/aconfig v0.18.5/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions aconfigtoml/testdata/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
foo = "value1"
bar = "value2"
[[foobar]]
foo = "slice_foo"
bar = "slice_bar"
4 changes: 2 additions & 2 deletions aconfigtoml/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package aconfigtoml
import (
"io/fs"

"github.com/BurntSushi/toml"
"github.com/pelletier/go-toml/v2"
)

// Decoder of TOML files for aconfig.
Expand All @@ -28,7 +28,7 @@ func (d *Decoder) DecodeFile(filename string) (map[string]interface{}, error) {
defer f.Close()

var raw map[string]interface{}
if _, err := toml.DecodeReader(f, &raw); err != nil {
if err := toml.NewDecoder(f).Decode(&raw); err != nil {
return nil, err
}
return raw, nil
Expand Down
8 changes: 6 additions & 2 deletions aconfigtoml/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ var configEmbed embed.FS

func TestTOMLEmbed(t *testing.T) {
var cfg struct {
Foo string
Bar string
Foo string
Bar string
Foobar []struct {
Foo string
Bar string
}
}
loader := aconfig.LoaderFor(&cfg, aconfig.Config{
SkipDefaults: true,
Expand Down
Loading