goverter
goverter copied to clipboard
interface level option inheritance
Let's consider example based on code generated by grpc that adds 3 additional fields state, sizeCache and unknownFields to every generated structure. In case when I've defined interface that will translate multiple structures I have to repeat myself on every structure to ignore those fields and additionally matchIgnoreCase. It would be cool to be able to define ignore and matchIgnoreCase at the level of interface so that every method has them in common defined.
Instead of:
type Transformer interface {
//goverter:matchIgnoreCase
//goverter:ignore state
//goverter:ignore sizeCache
//goverter:ignore unknownFields
Value(in.Struct1) out.Struct1
//goverter:matchIgnoreCase
//goverter:ignore state
//goverter:ignore sizeCache
//goverter:ignore unknownFields
Value(in.Struct2) out.Struct2
//goverter:matchIgnoreCase
//goverter:ignore state
//goverter:ignore sizeCache
//goverter:ignore unknownFields
Value(in.Struct3) out.Struct3
}
do this:
//goverter:matchIgnoreCase
//goverter:ignore state
//goverter:ignore sizeCache
//goverter:ignore unknownFields
type Transformer interface {
Value(in.Struct1) out.Struct1
Value(in.Struct2) out.Struct2
Value(in.Struct3) out.Struct3
}
I agree, it should be possible to set these options globally.
When you run goverter, you can pass -ignoreUnexportedFields, to automatically ignore all unexported fields. I feel like globally ignoring exported fields should be a rare use-case, and can possibly lead to unwanted behavior, thus, I'll close this issue.