diff --git a/.example/other/test.go b/.example/other/test.go index 2c8a90f3d..1ffd72098 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,21 +1,23 @@ package main import ( + "encoding/json" "fmt" + "gopkg.in/yaml.v3" ) -func Test() (int, int) { - return 1, 1 -} - -func Assert(v1, v2, v3 interface{}) { - fmt.Println(v1) -} - -func F(v ...interface{}) []interface{} { - return v -} - func main() { - Assert(F(Test()), 2, 3) + data := []byte(` +m: + k: v + `) + var result map[string]interface{} + if err := yaml.Unmarshal(data, &result); err != nil { + panic(err) + } + b, err := json.Marshal(result) + if err != nil { + panic(err) + } + fmt.Println(string(b)) } diff --git a/encoding/gyaml/gyaml.go b/encoding/gyaml/gyaml.go index e1fbf8864..feaeb6798 100644 --- a/encoding/gyaml/gyaml.go +++ b/encoding/gyaml/gyaml.go @@ -9,8 +9,8 @@ package gyaml import ( "encoding/json" + "gopkg.in/yaml.v3" - "github.com/gf-third/yaml" "github.com/gogf/gf/util/gconv" ) diff --git a/encoding/gyaml/gyaml_test.go b/encoding/gyaml/gyaml_test.go index d5dc22954..384ae4df3 100644 --- a/encoding/gyaml/gyaml_test.go +++ b/encoding/gyaml/gyaml_test.go @@ -3,9 +3,11 @@ // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. + package gyaml_test import ( + "encoding/json" "testing" "github.com/gogf/gf/encoding/gparser" @@ -81,6 +83,20 @@ func Test_DecodeError(t *testing.T) { }) } +func Test_DecodeMapToJson(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + data := []byte(` +m: + k: v + `) + v, err := gyaml.Decode(data) + t.Assert(err, nil) + b, err := json.Marshal(v) + t.Assert(err, nil) + t.Assert(b, `{"m":{"k":"v"}}`) + }) +} + func Test_ToJson(t *testing.T) { gtest.C(t, func(t *gtest.T) { m := make(map[string]string) diff --git a/go.mod b/go.mod index b643eba10..f6db30b1e 100644 --- a/go.mod +++ b/go.mod @@ -7,14 +7,14 @@ require ( github.com/clbanning/mxj v1.8.4 github.com/fatih/structs v1.1.0 github.com/fsnotify/fsnotify v1.4.7 - github.com/gf-third/yaml v1.0.1 github.com/go-sql-driver/mysql v1.5.0 github.com/gomodule/redigo v2.0.0+incompatible github.com/google/uuid v1.1.1 github.com/gorilla/websocket v1.4.1 github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf - github.com/mattn/go-runewidth v0.0.7 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect github.com/olekukonko/tablewriter v0.0.1 - golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e // indirect + golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect golang.org/x/text v0.3.2 + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c )