Collections and Composite Types
Structs
Structs group named fields into one value.
Structs
structs_intro.go
package main
import "fmt"
type User struct {
Name string
Age int
}
func main() {
var age =
user := User{Name: "Ada", Age: age}
label := fmt.Sprintf("%s:%d", user.Name, user.Age)
fmt.Println("name=", user.Name)
fmt.Println("age=", user.Age)
fmt.Println("label=", label)
}
package main
import "fmt"
type User struct {
Name string
Age int
}
func main() {
var age =
user := User{Name: "Ada", Age: age}
label := fmt.Sprintf("%s:%d", user.Name, user.Age)
fmt.Println("name=", user.Name)
fmt.Println("age=", user.Age)
fmt.Println("label=", label)
}
package main
import "fmt"
type User struct {
Name string
Age int
}
func main() {
var age =
user := User{Name: "Ada", Age: age}
label := fmt.Sprintf("%s:%d", user.Name, user.Age)
fmt.Println("name=", user.Name)
fmt.Println("age=", user.Age)
fmt.Println("label=", label)
}
struct field
A struct field stores one named part of a larger value.