Setting: useZeroValueOnPointerInconsistency
useZeroValueOnPointerInconsistency [yes,no]
is a boolean setting and can be defined as CLI argument, conversion comment or method comment. This setting is inheritable.
By default, goverter cannot automatically convert *T
to T
because it's unclear how nil
should be handled. T
in this example can be any type.
Enable useZeroValueOnPointerInconsistency
to instruct goverter to use the zero value of T
when having the problem above. See zero values | Go docs
go
package example
// goverter:converter
type Converter interface {
// goverter:useZeroValueOnPointerInconsistency
Convert(source Input) Output
}
type Input struct {
Name *string
Age int
}
type Output struct {
Name string
Age int
}
go
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
//go:build !goverter
package generated
import usezerovalueonpointerinconsistency "github.com/jmattheis/goverter/example/use-zero-value-on-pointer-inconsistency"
type ConverterImpl struct{}
func (c *ConverterImpl) Convert(source usezerovalueonpointerinconsistency.Input) usezerovalueonpointerinconsistency.Output {
var exampleOutput usezerovalueonpointerinconsistency.Output
if source.Name != nil {
exampleOutput.Name = *source.Name
}
exampleOutput.Age = source.Age
return exampleOutput
}