I have struct like
type Coverage struct {
neoCoverage []NeoCoverage
ApocCoverage []ApocCoverage
ApocConfigCoverage []ApocConfigCoverage
}
And
type NeoCoverage struct {
Name string
Number string
}
So how should i fill coverage struct?
Here how I am Trying.
coverage = Coverage{
[]neoCoverage: NeoCoverage{
Name: "xyz",
Number: "xyz123",
},
}
Something like below
package main
import "fmt"
func main() {
type NeoCoverage struct {
Name string
Number string
}
type Coverage struct {
neoCoverage []NeoCoverage
}
coverage := Coverage {
neoCoverage: []NeoCoverage {
NeoCoverage{ Name: "xyz", Number: "xyz123" },
NeoCoverage{ Name: "abc", Number: "abc123" },
},
}
fmt.Println(coverage)
}
Output
{[{xyz xyz123} {abc abc123}]}
Here is the brief explanation; neoCoverage: []NeoCoverage{}
stands for the slice of NeoCoverage
and that slice should be populated with NeoCoverage{}
elements as in NeoCoverage{ Name: "xyz", Number: "xyz123" }, ...
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