From f8a13cf704503ef953c0bb47ad5bf493f048734a Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 1 Jan 2022 16:48:46 +0100 Subject: [PATCH] feat(encoding): experimental yaml v3 library support --- .github/workflows/ci.yml | 5 +++-- go.mod | 2 +- internal/encoding/yaml/codec.go | 2 +- internal/encoding/yaml/yaml2.go | 14 ++++++++++++++ internal/encoding/yaml/yaml3.go | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 internal/encoding/yaml/yaml2.go create mode 100644 internal/encoding/yaml/yaml3.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 263b9eb..3b59d89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] go: ['1.14', '1.15', '1.16', '1.17'] + tags: ['', 'viper_yaml3'] env: GOFLAGS: -mod=readonly @@ -30,11 +31,11 @@ jobs: uses: actions/checkout@v2 - name: Test - run: go test -race -v ./... + run: go test -race -tags '${{ matrix.tags }}' -v ./... if: runner.os != 'Windows' - name: Test (without race detector) - run: go test -v ./... + run: go test -tags '${{ matrix.tags }}' -v ./... if: runner.os == 'Windows' lint: diff --git a/go.mod b/go.mod index f5b2cb6..608a0a6 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/subosito/gotenv v1.2.0 gopkg.in/ini.v1 v1.66.2 gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) require ( @@ -65,5 +66,4 @@ require ( google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect google.golang.org/grpc v1.43.0 // indirect google.golang.org/protobuf v1.27.1 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/internal/encoding/yaml/codec.go b/internal/encoding/yaml/codec.go index 5fa4b39..24cc19d 100644 --- a/internal/encoding/yaml/codec.go +++ b/internal/encoding/yaml/codec.go @@ -1,6 +1,6 @@ package yaml -import "gopkg.in/yaml.v2" +// import "gopkg.in/yaml.v2" // Codec implements the encoding.Encoder and encoding.Decoder interfaces for YAML encoding. type Codec struct{} diff --git a/internal/encoding/yaml/yaml2.go b/internal/encoding/yaml/yaml2.go new file mode 100644 index 0000000..ca29b84 --- /dev/null +++ b/internal/encoding/yaml/yaml2.go @@ -0,0 +1,14 @@ +//go:build !viper_yaml3 +// +build !viper_yaml3 + +package yaml + +import yamlv2 "gopkg.in/yaml.v2" + +var yaml = struct { + Marshal func(in interface{}) (out []byte, err error) + Unmarshal func(in []byte, out interface{}) (err error) +}{ + Marshal: yamlv2.Marshal, + Unmarshal: yamlv2.Unmarshal, +} diff --git a/internal/encoding/yaml/yaml3.go b/internal/encoding/yaml/yaml3.go new file mode 100644 index 0000000..96b8957 --- /dev/null +++ b/internal/encoding/yaml/yaml3.go @@ -0,0 +1,14 @@ +//go:build viper_yaml3 +// +build viper_yaml3 + +package yaml + +import yamlv3 "gopkg.in/yaml.v3" + +var yaml = struct { + Marshal func(in interface{}) (out []byte, err error) + Unmarshal func(in []byte, out interface{}) (err error) +}{ + Marshal: yamlv3.Marshal, + Unmarshal: yamlv3.Unmarshal, +}