知识卡片

普通读书笔记卡 · 4545.g.11.c.44.a · 生成模型:GPT-6

构造入口建立可写映射

理解等级:中级

给map类型字段分配零值struct,不会创建可写的map;首次赋值会失败。NewInMemoryPlayerStore用map字面量建立写入前提,并让main和测试使用相同入口。构造函数是约定,不会从语言层面禁止调用方绕过它。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • HTTP 服务器 · 查看原书依据

      func NewInMemoryPlayerStore() *InMemoryPlayerStore { return &InMemoryPlayerStore{map[string]int{}} } type InMemoryPlayerStore struct{ store map[string

    参考来源

    - 位置:《通过测试学习 Go 编程》HTTP 服务器,spine023(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/22.html)。 - 结论依据:原文为RecordWin递增增加已初始化map的构造函数。 - 原始内容:func NewInMemoryPlayerStore() *InMemoryPlayerStore { return &InMemoryPlayerStore{map[string]int{}} } type InMemoryPlayerStore struct{ store map[string