golang make an array of struct code example
Example: how to make struct type as array in go
package main
import (
"fmt"
"reflect"
)
type rectangle struct {
length float64
breadth float64
color string
}
func main() {
var rect1 = rectangle{10, 20, "Green"}
fmt.Println(reflect.TypeOf(rect1))
fmt.Println(reflect.ValueOf(rect1).Kind())
rect2 := rectangle{length: 10, breadth: 20, color: "Green"}
fmt.Println(reflect.TypeOf(rect2))
fmt.Println(reflect.ValueOf(rect2).Kind())
rect3 := new(rectangle)
fmt.Println(reflect.TypeOf(rect3))
fmt.Println(reflect.ValueOf(rect3).Kind())
var rect4 = &rectangle{}
fmt.Println(reflect.TypeOf(rect4))
fmt.Println(reflect.ValueOf(rect4).Kind())
}