Explorar el Código

Support "-" tag.

Gustavo Niemeyer hace 13 años
padre
commit
e720624475
Se han modificado 3 ficheros con 17 adiciones y 0 borrados
  1. 7 0
      decode_test.go
  2. 7 0
      encode_test.go
  3. 3 0
      goyaml.go

+ 7 - 0
decode_test.go

@@ -125,6 +125,13 @@ var unmarshalTests = []struct {
 	// BUG #1133337
 	{"foo: ''", map[string]*string{"foo": new(string)}},
 	{"foo: null", map[string]string{}},
+
+	// Ignored field
+	{"a: 1\nb: 2\n",
+		&struct {
+			A int
+			B int "-"
+		}{1, 0}},
 }
 
 func (s *S) TestUnmarshal(c *C) {

+ 7 - 0
encode_test.go

@@ -104,6 +104,13 @@ var marshalTests = []struct {
 			u int
 			A int
 		}{0, 1}},
+
+	// Ignored field
+	{"a: 1\n",
+		&struct {
+			A int
+			B int "-"
+		}{1, 2}},
 }
 
 func (s *S) TestMarshal(c *C) {

+ 3 - 0
goyaml.go

@@ -187,6 +187,9 @@ func getStructFields(st reflect.Type) (*structFields, error) {
 		if tag == "" && strings.Index(string(field.Tag), ":") < 0 {
 			tag = string(field.Tag)
 		}
+		if tag == "-" {
+			continue
+		}
 
 		// XXX Drop this after a few releases.
 		if s := strings.Index(tag, "/"); s >= 0 {