Reuse json tags while decoding map to struct

main
Pranav Karawale 5 months ago
parent 4b0e7d53c9
commit 2b6a66858a
Signed by: pranav
GPG Key ID: 1A551FFE981F09AB

@ -128,7 +128,14 @@ func Jf2ToPost(jf2 microformats.Jf2) (Post, error) {
return post, err
}
normalized["kind"] = getPostKind(normalized)
if err = mapstructure.Decode(normalized, &post); err != nil {
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
TagName: "json",
Result: &post,
})
if err != nil {
return post, err
}
if err = decoder.Decode(normalized); err != nil {
return post, fmt.Errorf("%w: %s", ErrorInvalidPost, err.Error())
}
validate := validator.New()

Loading…
Cancel
Save