package main
import (
"fmt"
)
type demo []struct {
Text string
Type string
}
func main() {
d := demo{
Text: "Hello",
Type: "string",
}
}
In this code I'm getting an error while declaring the object of demo
struct:
./prog.go:11:3: undefined: Text
./prog.go:11:9: cannot use "Hello" (untyped string constant) as struct{Text string; Type string} value in array or slice literal
./prog.go:12:3: undefined: Type
./prog.go:12:9: cannot use "string" (untyped string constant) as struct{Text string; Type string} value in array or slice literal
it's obvious because it is not a normal struct declaration so please help me how can I construct object of demo
struct?
d
as a single struct. Do you want thedemo
type to be a single struct or a slice of them?