Update go-toml to v2

Updates host file parsing to use new v2 method rather than the removed
toml.Tree.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2023-09-22 12:29:26 -07:00
parent e0e6f870b7
commit b5615caf11
78 changed files with 7586 additions and 5876 deletions

View File

@@ -24,7 +24,7 @@ import (
"os"
"github.com/docker/go-units"
"github.com/pelletier/go-toml"
"github.com/pelletier/go-toml/v2"
)
// Config represents device mapper configuration loaded from file.
@@ -55,21 +55,19 @@ type Config struct {
// LoadConfig reads devmapper configuration file from disk in TOML format
func LoadConfig(path string) (*Config, error) {
if _, err := os.Stat(path); err != nil {
f, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
return nil, os.ErrNotExist
}
return nil, err
}
defer f.Close()
config := Config{}
file, err := toml.LoadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to open devmapepr TOML: %s: %w", path, err)
}
if err := file.Unmarshal(&config); err != nil {
if err := toml.NewDecoder(f).Decode(&config); err != nil {
return nil, fmt.Errorf("failed to unmarshal devmapper TOML: %w", err)
}

View File

@@ -22,7 +22,7 @@ import (
"os"
"testing"
"github.com/pelletier/go-toml"
"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
)