Golang中的Map与值数组

huangapple go评论68阅读模式
英文:

Golang Map with array of values

问题

这个Go语言语句的含义是:创建了一个空的map类型变量bookMap,其键类型为string,值类型为[]*model.Books。这个map变量属于Student结构体类型。

在这里,Student是一个结构体类型,它包含了一个名为bookMap的成员变量,其类型为map[string][]*model.Books

同时,我们还有一个model包,其中定义了Books结构体类型。Books结构体包含了bookNamebookAuthor两个成员变量,它们的类型分别为string,并且使用了db:"Name"db:"Author"的标签。

英文:

What does this statement mean in Go:

Student.bookMap=map[string][]*model.Books{}

Where Student is:

type Student struct{
    bookMap map[string][]*model.Books
}

and we have a model package

package model

type Books struct {
    bookName   string  `db:"Name"`
    bookAuthor string  `db:"Author"`
}

答案1

得分: 1

该语句将地图Student.bookMap初始化为空地图(其结构如下:键 -> string,值 -> model.Books指针的切片)。

英文:

That statement is initializing the map Student.bookMap to an empty map (which has the following structure: key -> string, value -> slice of pointers of model.Books).

答案2

得分: 0

这意味着struct类型的Student中的成员bookMap包含一个map,该mapstring作为,以指向model.Books实例的指针数组(切片)作为

英文:

It means the member bookMap of a struct Student contains a map which takes a string as a key, and an array (slice) of pointers to instances of model.Books as value.

huangapple
  • 本文由 发表于 2016年11月18日 19:02:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/40675421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定