jmattheis / goverter

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

Nested Protos types #131

Closed rwalerow closed 8 months ago

rwalerow commented 8 months ago

Have you read the project documentation?

Describe your question How should I write converter for nested protos types

Source code From those types:

type PerSeverityResponseData struct {
    TotalAmount int32
    Severities  []Severity
}

type Severity struct {
    Severity string
    Amount   int32
}

Into those protos type?

message Severity {
  string severity = 1;
  int32 amount = 2;
}

message PerSeverityResponse {
  int32 total = 1;
  repeated Severity severities = 2;
}

I've tried something like this but it didn't work

// goverter:converter
// goverter:output:file ./mappersGenerated.go
// goverter:output:package samepackage here
type Converter interface {

    // goverter:map TotalAmount Total
    // goverter:ignoreUnexported
    ByHighSeverityToProtobuf(*PerSeverityResponseData) *PerSeverityResponse
}
jmattheis commented 8 months ago

Does this help? https://goverter.jmattheis.de/guide/configure-nested

rwalerow commented 7 months ago

I've found the solution for this issue, but configure nested is not satisfactorily, since the example I provided is very simple, only one level nested. What if somebody has to deal with structure 3 or 4 levels deep? That would require a lot of configuration. I've manged to solve my issue with // goverter:ignoreUnexported but on interface level