From be91749a25358789bfc4f177238b79cd2afe11d2 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 13 Nov 2019 12:14:49 +0900 Subject: [PATCH] Remove tag handling without identifier --- decode_test.go | 2 +- encode_test.go | 28 ++++++++++++++-------------- struct.go | 3 --- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/decode_test.go b/decode_test.go index 132a6a99..7e992fec 100644 --- a/decode_test.go +++ b/decode_test.go @@ -591,7 +591,7 @@ func TestDecoder(t *testing.T) { { "a: 1", struct { - B int "a" + B int `yaml:"a"` }{1}, }, diff --git a/encode_test.go b/encode_test.go index 9e65d17c..930f5bb3 100644 --- a/encode_test.go +++ b/encode_test.go @@ -212,56 +212,56 @@ func TestEncoder(t *testing.T) { { "a: 1\n", struct { - A int "a,omitempty" - B int "b,omitempty" + A int `yaml:"a,omitempty"` + B int `yaml:"b,omitempty"` }{1, 0}, }, { "{}\n", struct { - A int "a,omitempty" - B int "b,omitempty" + A int `yaml:"a,omitempty"` + B int `yaml:"b,omitempty"` }{0, 0}, }, { "a: {x: 1}\n", struct { - A *struct{ X, y int } "a,omitempty,flow" + A *struct{ X, y int } `yaml:"a,omitempty,flow"` }{&struct{ X, y int }{1, 2}}, }, { "{}\n", struct { - A *struct{ X, y int } "a,omitempty,flow" + A *struct{ X, y int } `yaml:"a,omitempty,flow"` }{nil}, }, { "a: {x: 0}\n", struct { - A *struct{ X, y int } "a,omitempty,flow" + A *struct{ X, y int } `yaml:"a,omitempty,flow"` }{&struct{ X, y int }{}}, }, { "a: {x: 1}\n", struct { - A struct{ X, y int } "a,omitempty,flow" + A struct{ X, y int } `yaml:"a,omitempty,flow"` }{struct{ X, y int }{1, 2}}, }, { "{}\n", struct { - A struct{ X, y int } "a,omitempty,flow" + A struct{ X, y int } `yaml:"a,omitempty,flow"` }{struct{ X, y int }{0, 1}}, }, { "a: 1.0\n", struct { - A float64 "a,omitempty" - B float64 "b,omitempty" + A float64 `yaml:"a,omitempty"` + B float64 `yaml:"b,omitempty"` }{1, 0}, }, @@ -269,13 +269,13 @@ func TestEncoder(t *testing.T) { { "a: [1, 2]\n", struct { - A []int "a,flow" + A []int `yaml:"a,flow"` }{[]int{1, 2}}, }, { "a: {b: c, d: e}\n", &struct { - A map[string]string "a,flow" + A map[string]string `yaml:"a,flow"` }{map[string]string{"b": "c", "d": "e"}}, }, { @@ -283,7 +283,7 @@ func TestEncoder(t *testing.T) { struct { A struct { B, D string - } "a,flow" + } `yaml:"a,flow"` }{struct{ B, D string }{"c", "e"}}, }, diff --git a/struct.go b/struct.go index c4f1fb81..5040031c 100644 --- a/struct.go +++ b/struct.go @@ -27,9 +27,6 @@ type StructField struct { func structField(field reflect.StructField) *StructField { tag := field.Tag.Get(StructTagName) - if tag == "" && strings.Index(string(field.Tag), ":") < 0 { - tag = string(field.Tag) - } fieldName := strings.ToLower(field.Name) options := strings.Split(tag, ",") if len(options) > 0 {