💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
> # []struct{} 如何遍历 ~~~ package main import "fmt" type Item struct { Id int Val string } func main() { item := make([]Item, 0, 1024) for i := 0; i < 1000; i++ { item = append(item, Item{ Id: i, Val: fmt.Sprintf("%d", i), }) } //遍历1 for k, v := range item { _ = v //值类型会拷贝 _ = k } //遍历1 for k, _ := range item { _ = item[k] //不会拷贝副本 _ = k } item2 := make([]*Item, 0, 1024) for i := 0; i < 1000; i++ { item2 = append(item2, &Item{ Id: i, Val: fmt.Sprintf("%d", i), }) } for k, v := range item2 { _ = v //指针不会 拷贝副本 _ = k } } ~~~