jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
496 stars 46 forks source link

Possibility of matchIgnoreCase for enums #157

Closed sublee closed 1 month ago

sublee commented 1 month ago

Have you read the project documentation?

Describe your question A clear and concise description of what the question is.

goverter:matchIgnoreCase cannot be used for enums members. It supports structs only. I'd like to know the design decision behind this behavior. Is the current behavior inevitable? Or, should it support both enums and structs in the future?

Source code Include source code to give context for your question.

const (
    MethodGetID Method = iota
    MethodPutID
)

// The pb package has corresponding enum members but "Id" instead of "ID".
// pb.MethodGetId
// pb.MethodPutId

// goverter:variables
var (
    // goverter:enum:unknown METHOD_UNSPECIFIED
    // goverter:matchIgnoreCase
    ConvertMethod(Method) pb.Method
)

Errors Include errors that occur while you run goverter.

Invalid struct field mapping on method:
    /.../example.go:25
    var ConvertMethod func(Method) pb.Method

Field mappings like goverter:map or goverter:ignore may only be set on struct or struct pointers.
See https://goverter.jmattheis.de/guide/configure-nested
exit status 1
...: running "go": exit status 1
jmattheis commented 1 month ago

I'm not 100% sure anymore, maybe because matchIgnoreCase is defined as case insensitive field matching and enum values aren't really fields.

That said, I'm not against adding the matchIgnoreCase feature to enums with the same setting.

sublee commented 1 month ago

Thanks for sharing your opinion. I'll open a separate issue of the feature request. I think I can implement the feature in a few days.