知识卡片
上下文值限于请求信息
WithValue把键值附加到派生上下文,可用于沿请求传递必要信息。它不提供显式参数那样的静态约束,隐含依赖也会掩盖流程,因此不应把必需配置或控制行为的任意参数塞入其中。键值缺失的含义和类型应明确,取消协调与数据传递是不同责任。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Cloud Native Patterns · 查看原书依据
The context.WithValue and context.Value functions provide convenient mechanisms for setting and getting arbitrary key-value pairs that can be used by consuming processes and APIs. However, it has been argued that this functionality is orthogonal to Context’s function of orchestrating the cancelation of long-lived requests, obscures your program’s flow, and can easily break compile-time coupling. For
参考来源
- 位置:《Cloud Native Go》第04章《Cloud Native Patterns》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch04.xhtml)
- 结论依据:WithValue把键值附加到派生上下文,可用于沿请求传递必要信息。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:The context.WithValue and context.Value functions provide convenient mechanisms for setting and getting arbitrary key-value pairs that can be used by consuming processes and APIs. However, it has been argued that this functionality is orthogonal to Context’s function of orchestrating the cancelation of long-lived requests, obscures your program’s flow, and can easily break compile-time coupling. For