Declare, create and initialize struct types
// Sample program to show how to declare and initialize struct types.
package main
import "fmt"
// example represents a type with different fields.
//示例表示具有不同字段的类型。
type example struct {
flag bool
counter int16
pi float32
}
func main() {
// Declare a variable of type example set to its
// zero value.
var e1 example
// display the value
fmt.Printf("%+v\n", e1)
// Declare a variable of type example and init using
// a struct literal.
e2 := example{
flag: true,
counter: 11,
pi: 3.14159,
}
// display the field values
fmt.Println("flag", e2.flag)
fmt.Println("counter", e2.counter)
fmt.Println("pi", e2.pi)
/*
{flag:false counter:0 pi:0}
flag true
counter 11
pi 3.14159
*/
}