golang 切片

空切片 package main import "fmt" func main() { // Declare a nil slice var x []int fmt.Println(x, len(x), cap(x)) x = append(x, 10, 20, 30) fmt.Println("Slice x after appending data:", …

golang map

map 的初始化方式 方式一 // Declares a nil map var chapts map[int]string // Initialize map with make function chapts = make(map[int]string) // Add data as key/value pairs chapts[1] = “Beginning Go” chapts[2] = …

golang 空接口

不使用接口的遍历 package main import "fmt" type vehicle struct { Seats int MaxSpeed int Color string } type car struct { vehicle Wheels int Doors int } type plane struct { vehicle Jet bool } type bo …

golang 结构体

结构体初始化 package main import “fmt” type person struct { first string last string age int } func main() { p1 := person{“James”, “Bond”, 20} p2 := person{“Miss”, “Moneypenny”, 18} fmt.Println(p1.first, p1 …