Skip to content

Commit

Permalink
feat(encoding): experimental yaml v3 library support
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Jan 1, 2022
1 parent 9934fe7 commit ea18671
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -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

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion 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{}
Expand Down
14 changes: 14 additions & 0 deletions 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,
}
14 changes: 14 additions & 0 deletions 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,
}

0 comments on commit ea18671

Please sign in to comment.