Add option to disallow unknown fields

This commit is contained in:
Jack Lee
2023-02-21 02:02:04 -05:00
parent 7fa4b32dd0
commit e717b9c6db
3 changed files with 32 additions and 5 deletions

View File

@ -33,7 +33,8 @@ type DecoderReader = interface {
io.Reader
}
type Decoder struct {
r DecoderReader
r DecoderReader
disallowUnknownFields bool
}
func NewDecoder(r io.Reader) *Decoder {
@ -46,6 +47,12 @@ func NewDecoder(r io.Reader) *Decoder {
return d
}
// DisallowUnknownFields makes the decoder return an error when unmarshalling a compound
// tag item that has a tag name not present in the destination struct.
func (d *Decoder) DisallowUnknownFields() {
d.disallowUnknownFields = true
}
type reader struct {
io.Reader
}