I have a simple structure:
type MyWriter struct {
io.Writer
}
Which I then use in the following way:
writer = MyWriter{io.Stdout}
When running go vet
this gives me a composite literal uses unkeyed fields
.
In order to fix this would I have to turn io.Reader into a field in the MyWriter
structure by adding a key?
type MyWriter struct {
w io.Writer
}
Is there any other way around this? The only other answer I found on here suggests to disable the check altogether but I would rather not do that and find a proper solution.
Try this:
writer = MyWriter{Writer: io.Stdout}
Embedded structs have an implicit key of the type name itself without the package prefix (e.g. in this case, Writer
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With