mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-21 10:03:40 +08:00
Merge 39e1cae4073c5fa466c7e33e3ead672099144c96 into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646
This commit is contained in:
commit
07474057a5
@ -117,8 +117,11 @@ func (c *Context) reset() {
|
||||
*c.skippedNodes = (*c.skippedNodes)[:0]
|
||||
}
|
||||
|
||||
// Copy returns a copy of the current context that can be safely used outside the request's scope.
|
||||
// Copy returns a copy of the current context for use outside the request's scope.
|
||||
// This has to be used when the context has to be passed to a goroutine.
|
||||
//
|
||||
// The copy's underlying http.ResponseWriter is nil, so it cannot write the HTTP response.
|
||||
// Do not call response-writing methods such as JSON, String, or Stream on the copy.
|
||||
func (c *Context) Copy() *Context {
|
||||
cp := Context{
|
||||
writermem: c.writermem,
|
||||
|
||||
@ -617,6 +617,8 @@ func main() {
|
||||
|
||||
When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** use the original context inside it, you have to use a read-only copy.
|
||||
|
||||
The copy's underlying `http.ResponseWriter` is `nil`, so it cannot write the HTTP response. Do not call response-writing methods such as `JSON`, `String`, or `Stream` on the copy. Write the response from the original handler before it returns.
|
||||
|
||||
```go
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user