Skip to content

Commit 0302d8c

Browse files
committed
refactor: remove yaml.v2
1 parent adfbc6c commit 0302d8c

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

cmd/dump.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/natesales/pathvector/pkg/process"
6-
"github.com/natesales/pathvector/pkg/util"
75
"os"
86
"strings"
97

108
log "github.com/sirupsen/logrus"
119
"github.com/spf13/cobra"
1210
"gopkg.in/yaml.v3"
11+
12+
"github.com/natesales/pathvector/pkg/process"
13+
"github.com/natesales/pathvector/pkg/util"
1314
)
1415

1516
var (

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/spf13/cobra v1.2.1
1212
github.com/stretchr/testify v1.7.0
1313
golang.org/x/mod v0.4.2
14-
gopkg.in/yaml.v2 v2.4.0
1514
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
1615
)
1716

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
599599
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
600600
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
601601
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
602-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
603602
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
604603
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
605604
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=

pkg/process/process.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/creasty/defaults"
2323
"github.com/go-playground/validator/v10"
2424
log "github.com/sirupsen/logrus"
25-
"gopkg.in/yaml.v2"
2625

2726
"github.com/natesales/pathvector/pkg/config"
2827
"github.com/natesales/pathvector/pkg/plugin"
@@ -106,7 +105,7 @@ func Load(configBlob []byte) (*config.Config, error) {
106105
c.Init()
107106
defaults.MustSet(&c)
108107

109-
if err := yaml.UnmarshalStrict(configBlob, &c); err != nil {
108+
if err := util.YAMLUnmarshalStrict(configBlob, &c); err != nil {
110109
return nil, fmt.Errorf("YAML unmarshal: %s", err)
111110
}
112111

pkg/util/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package util
22

33
import (
4+
"bytes"
45
"io"
56
"os"
67
"path/filepath"
@@ -10,6 +11,7 @@ import (
1011

1112
"github.com/olekukonko/tablewriter"
1213
log "github.com/sirupsen/logrus"
14+
"gopkg.in/yaml.v3"
1315
)
1416

1517
var alphabet = strings.Split("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "")
@@ -193,3 +195,10 @@ func CopyFileGlob(glob, dest string) error {
193195
}
194196
return nil
195197
}
198+
199+
// YAMLUnmarshalStrict unmarshals a YAML file into a struct
200+
func YAMLUnmarshalStrict(y []byte, v interface{}) error {
201+
decoder := yaml.NewDecoder(bytes.NewReader(y))
202+
decoder.KnownFields(true)
203+
return decoder.Decode(v)
204+
}

0 commit comments

Comments
 (0)