知识卡片
参数对象说明配置职责
很多同类型字符串参数难以从调用处辨认顺序,配置结构可用命名字段表达主机、库名和身份等职责,便于扩展和核对。结构本身不解决密钥管理;原书硬编码密码仅是演示,运行配置和凭据不应因包装进结构就被当作安全。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Building a Cloud Native Service · 查看原书依据
Unlike the big bag of strings approach, the above struct is small, readable, and easily extended. To use it we’d create a PostgresDbParams variable and pass it to our construction function. Here’s what that looks like: transact, err = NewPostgresTransactionLogger(PostgresDbParams{ host: "localhost", dbName: "kvs", user: "test", password: "hunter2" }) Our new construction function looks something
参考来源
- 位置:《Cloud Native Go》第05章《Building a Cloud Native Service》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch05.xhtml)
- 结论依据:很多同类型字符串参数难以从调用处辨认顺序,配置结构可用命名字段表达主机、库名和身份等职责,便于扩展和核对。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:Unlike the big bag of strings approach, the above struct is small, readable, and easily extended. To use it we’d create a PostgresDbParams variable and pass it to our construction function. Here’s what that looks like: transact, err = NewPostgresTransactionLogger(PostgresDbParams{ host: "localhost", dbName: "kvs", user: "test", password: "hunter2" }) Our new construction function looks something