The following code works, but I want to find a simpler way to do it
package main
import "fmt"
type steps []struct {
i int
j int
}
func main() {
steps := steps{}
type step struct{ i, j int }
steps = append(steps, step{1, 1}, step{1, 2})
fmt.Println(steps)
}
Specifically, I don't want to define a new type just so I can append it to a slice. For example, I want to do it like this:
package main
import "fmt"
type steps []struct {
i int
j int
}
func main() {
steps := steps{}
steps = append(steps, {1, 1}, {1, 2}) // syntax error
fmt.Println(steps)
}
But I'll get a "syntax error: unexpected {, expecting expression"
I don't understand why I can't do it this way, the data structure is correct.