Godantic failing on validator.BindJSON
Closed this issue · 1 comments
panic: reflect: call of reflect.Value.IsNil on string Value
goroutine 1 [running]:
reflect.Value.IsNil(...)
C:/Program Files/Go/src/reflect/value.go:1556
github.com/grahms/godantic.(*Validate).checkField(0xb83ce0?, {0xb83ce0?, 0xc0000747e0?, 0xb83ce0?}, {0xbbb9c8?, 0xb83ce0?}, {0x0, 0x0}, 0x0?)
C:/Users/Obadias Pelembe/go/pkg/mod/github.com/grahms/godantic@v1.0.0/structcheck.go:104 +0x445
github.com/grahms/godantic.(*Validate).inspect(0xb83ce0?, {0xb83ce0?, 0xc0000747e0?}, {0x0, 0x0})
C:/Users/Obadias Pelembe/go/pkg/mod/github.com/grahms/godantic@v1.0.0/structcheck.go:49 +0x5e9
github.com/grahms/godantic.(*Validate).inspect(0xc0000102c0?, {0xb756c0?, 0xc000074510?}, {0x0, 0x0})
C:/Users/Obadias Pelembe/go/pkg/mod/github.com/grahms/godantic@v1.0.0/structcheck.go:45 +0x1b4
github.com/grahms/godantic.(*Validate).InspectStruct(...)
C:/Users/Obadias Pelembe/go/pkg/mod/github.com/grahms/godantic@v1.0.0/structcheck.go:36
github.com/grahms/godantic.(*Validate).BindJSON(0xc000050058?, {0xc0000102c0, 0x3c, 0x3c}, {0xb756c0, 0xc000074510})
C:/Users/Obadias Pelembe/go/pkg/mod/github.com/grahms/godantic@v1.0.0/decoder.go:67 +0x11e
main.main()
C:/Users/Obadias Pelembe/Workspace/Contributions/cves-guard/internal/main.go:30 +0xd8
exit status 2
In attachment the sample code
Godantic requires that all your types are pointers for Nullability.
Nullability: Pointers can be nil, while non-pointer fields cannot. This means that if a field in the JSON is null or not present, it will be unmarshalled as nil in Go if the field is a pointer, but if it's not a pointer, it will be unmarshalled as the zero value of the field type. This behavior can be essential when you want to differentiate between a field that is not present in the JSON and a field that is present but has a zero value.