http - 在谈论 HTTP 请求时,Go lang 中的这个 CONTEXT 是什么?

标签 http go

对某些人来说,这可能是一个愚蠢的问题。另一方面,这对我来说非常重要。我是 Go 编程的新手,当我读到这篇文章时 Sharing values between Middlewares还有这个Go Concurrency Patterns: Context当提到在中间件处理程序或请求处理程序之间共享值时,我无法弄清楚 Context 到底是什么意思。

我已经能够使用 Go 编写 Web 框架 -- Frodo .在很多方面并不完美,这是一个学习实验。如你所见,我并不愚蠢。刚接触 Go 语言的消息不多。

提前感谢您的全面解释。

最佳答案

我在这个博客的开头找到了一个很好的解释:HTTP Request Contexts & Go

Request contexts, for those new to the terminology, are typically a way to pass data alongside a HTTP request as it is processed by handlers (or middleware) you have written. This data could be a user ID, a CSRF token, a web token, whether a user is logged in or not—something typically derived from logic that you don't want to repeat over-and-over again in every handler. If you've ever used Django, the request context is synonymous with the request.META dictionary.

关于http - 在谈论 HTTP 请求时,Go lang 中的这个 CONTEXT 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34658423/

相关文章:

javascript - HTTP 连接的 chrome.sockets.tcp.onReceiveError

go - 在 Go 中使用编码/二进制进行字节字节序转换

api - golang json 解码中的指针

go - 如何检查文件是否是 GoLang 中的 tar 文件?

go - Go编译器产生奇怪的加载到x0中

php - PHP处理脚本包含而不抑制其错误和警告

python - 如何使用 Python 脚本(请求库)保持登录网站?

http - HTTP Header 或 Response Body 中的 Rest 错误消息?

c# - C#中如何从另一个方法调用一个对象

go - 添加到 golang 类型中的匿名 slice