Skip to content

Commit 9c2eaae

Browse files
committed
docs: improve omitempty documentation.
Improves the documentation of the existing `omitempty` struct tag, as it relates to nil and empty slices.
1 parent 3965441 commit 9c2eaae

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mapstructure.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@
115115
//
116116
// When decoding from a struct to any other value, you may use the
117117
// ",omitempty" suffix on your tag to omit that value if it equates to
118-
// the zero value. The zero value of all types is specified in the Go
119-
// specification.
118+
// the zero value, or a zero-length element. The zero value of all types is
119+
// specified in the Go specification.
120120
//
121121
// For example, the zero type of a numeric type is zero ("0"). If the struct
122122
// field value is zero and a numeric type, the field is empty, and it won't
123-
// be encoded into the destination type.
123+
// be encoded into the destination type. And likewise for the URLs field, if the
124+
// slice is nil or empty, it won't be encoded into the destination type.
124125
//
125126
// type Source struct {
126-
// Age int `mapstructure:",omitempty"`
127+
// Age int `mapstructure:",omitempty"`
128+
// URLs []string `mapstructure:",omitempty"`
127129
// }
128130
//
129131
// # Unexported fields

0 commit comments

Comments
 (0)