code-generator
code-generator copied to clipboard
applyconfiguration-gen do not handle slices of pointers correctly
For the following struct:
type Foo struct {
Bar []*string `json:"bar,omitempty"`
}
applyconfiguration-gen generate the following "With" function:
func (b *Foo ) WithBar(values ...*string) *Bar{
for i := range values {
if values[i] == nil {
panic("nil value passed to WithBar")
}
b.Bar = append(b.Bar, *values[i])
}
return b
}
Which causes cannot use *values[i] (variable of type string) as *string value in argument to append
values[i]
should not be dereferenced.
The correct code is:
func (b *Foo ) WithBar(values ...*string) *Bar{
for i := range values {
if values[i] == nil {
panic("nil value passed to WithBar")
}
- b.Bar = append(b.Bar, *values[i])
+ b.Bar = append(b.Bar, values[i])
}
return b
}