context 包在 API 边界和 goroutine 之间传递取消信号、截止时间和请求作用域的值。它是控制操作生命周期的标准机制——特别是用于取消工作和通过函数调用链传播超时。
它解决的核心问题
text
A request starts work across many goroutines/functions (DB query, API call, etc.).
If the client disconnects or a timeout hits, you want to CANCEL all that work
so goroutines don't keep running uselessly (wasting resources / leaking).
→ context propagates the "stop now" signal down the entire call chain.
