Skip to content

Frequently Asked Questions

How to convert structs

See Guide: Struct

TypeMismatch: Cannot convert interface{} to interface{}

See below

TypeMismatch: Cannot convert any to any

Goverter doesn't know how to convert any to any or interface{} to interface{}, you need to define the mapping yourself. If you only want to pass the value without any conversion you can define it like this:

Example (click me)
go
package example

// goverter:converter
// goverter:extend ConvertAny
type Converter interface {
	Convert(Input) Output
}

func ConvertAny(value interface{}) interface{} {
	return value
}

type Input struct{ Value interface{} }
type Output struct{ Value interface{} }
go
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
//go:build !goverter

package generated

import anytoany "github.com/jmattheis/goverter/example/any-to-any"

type ConverterImpl struct{}

func (c *ConverterImpl) Convert(source anytoany.Input) anytoany.Output {
	var exampleOutput anytoany.Output
	exampleOutput.Value = anytoany.ConvertAny(source.Value)
	return exampleOutput
}