Skip to content

Commit ae32a61

Browse files
committed
doc: add more documentation
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
1 parent 320c8c9 commit ae32a61

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mapstructure.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@
173173
// Public: "I made it through!"
174174
// }
175175
//
176+
// # Custom Decoding with Unmarshaler
177+
//
178+
// Types can implement the Unmarshaler interface to control their own decoding. The interface
179+
// behaves similarly to how UnmarshalJSON does in the standard library. It can be used as an
180+
// alternative or companion to a DecodeHook.
181+
//
182+
// type TrimmedString string
183+
//
184+
// func (t *TrimmedString) UnmarshalMapstructure(input any) error {
185+
// str, ok := input.(string)
186+
// if !ok {
187+
// return fmt.Errorf("expected string, got %T", input)
188+
// }
189+
// *t = TrimmedString(strings.TrimSpace(str))
190+
// return nil
191+
// }
192+
//
193+
// See the Unmarshaler interface documentation for more details.
194+
//
176195
// # Other Configuration
177196
//
178197
// mapstructure is highly configurable. See the DecoderConfig struct

0 commit comments

Comments
 (0)