jmattheis / goverter

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

matchIgnoreCase for enum members #158

Open sublee opened 1 month ago

sublee commented 1 month ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

In Go, acronyms should be all capitals. But some codegen does not respect this rule. For example, protoc-gen-go generates ParentId rather than ParentID from parent_id. matchIgnoreCase is useful for mapping struct fields regardless of the case of names. But the problem occurs on enum members also, not only struct fields. Currently, matchIgnoreCase is not allowed on enum type converters.

// goverter:enum:unknown METHOD_UNSPECIFIED
// goverter:matchIgnoreCase
ConvertMethod func(Method) pb.Method
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

Describe the solution you'd like A clear and concise description of what you want to happen.

Extending matchIgnoreCase to support both struct fields and enum members. As discussed in #157, this modification does not look like violating the existing design decision.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

N/A