Skip to content

Support interface embedding for seperation of concerns #189

Description

@jooola

Is your feature request related to a problem? Please describe.

We maintain a large amount of functions for multiple kinds of "resources". We would like to make it easier to maintain by splitting the converter interfaces for each "resources" to improve the maintainability of this code.

Describe the solution you'd like

I'd like to be able to have a single goverter converter in which I embed an unlimited amount of interfaces for each of my resources:

package main

type Person struct {
	Name string
}

type PersonSchema struct {
	Name string
}

type PersonConverter interface {
	PersonFromSchema(PersonSchema) Person
	SchemaFromPerson(Person) PersonSchema
}

type Address struct {
	Street  string
	ZipCode string
}

type AddressSchema struct {
	Street  string
	ZipCode string
}

type AddressConverter interface {
	AddressFromSchema(AddressSchema) Address
	SchemaFromAddress(Address) AddressSchema
}

// goverter:converter
type Converter interface {
	PersonConverter
	AddressConverter
}

But this fails with:

$ go run github.com/jmattheis/goverter/cmd/goverter gen .         
/test.go:32:1: type Converter: method must have one name
exit status 1

Describe alternatives you've considered

We could use a different converter for each resources, but since we have resources that cross boundaries, we need to share the common converter configuration (and extends) for all our conversion and we prefer not to duplicate the goverter config.

Please 👍 this issue if you like this functionality. If you have a specific use-case in mind, feel free to comment it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions