Files
bitmagnet/internal/classifier/decoder.go
T
mgdigital c16f76130c Classifier rewrite (#213)
The classifier has been re-implemented and now uses a DSL allowing for full customisation. Several bugs have also been fixed.

- Closes https://github.com/bitmagnet-io/bitmagnet/issues/182
- Closes https://github.com/bitmagnet-io/bitmagnet/issues/70
- Closes https://github.com/bitmagnet-io/bitmagnet/issues/68
- Hopefully fixes https://github.com/bitmagnet-io/bitmagnet/issues/126
2024-04-21 16:24:10 +01:00

18 lines
401 B
Go

package classifier
import (
"github.com/iancoleman/strcase"
"github.com/mitchellh/mapstructure"
)
func newDecoder[T any](target *T) (*mapstructure.Decoder, error) {
return mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: target,
MatchName: func(mapKey, fieldName string) bool {
return mapKey == strcase.ToSnake(fieldName)
},
ErrorUnused: true,
TagName: "json",
})
}