MCPcopy
hub / github.com/gin-gonic/gin / Copy

Method Copy

context.go:122–145  ·  view source on GitHub ↗

Copy returns a copy of the current context that can be safely used outside the request's scope. This has to be used when the context has to be passed to a goroutine.

()

Source from the content-addressed store, hash-verified

120// Copy returns a copy of the current context that can be safely used outside the request's scope.
121// This has to be used when the context has to be passed to a goroutine.
122func (c *Context) Copy() *Context {
123 cp := Context{
124 writermem: c.writermem,
125 Request: c.Request,
126 engine: c.engine,
127 }
128
129 cp.writermem.ResponseWriter = nil
130 cp.Writer = &cp.writermem
131 cp.index = abortIndex
132 cp.handlers = nil
133 cp.fullPath = c.fullPath
134
135 cKeys := c.Keys
136 c.mu.RLock()
137 cp.Keys = maps.Clone(cKeys)
138 c.mu.RUnlock()
139
140 cParams := c.Params
141 cp.Params = make([]Param, len(cParams))
142 copy(cp.Params, cParams)
143
144 return &cp
145}
146
147// HandlerName returns the main handler's name. For example if the handler is "handleGetUsers()",
148// this function will return "main.handleGetUsers".

Callers 11

TestContextCopyFunction · 0.80
TestRaceContextCopyFunction · 0.80
captureOutputFunction · 0.80
SaveUploadedFileMethod · 0.80
RenderMethod · 0.80
setFormMapFunction · 0.80

Calls

no outgoing calls

Tested by 8

TestContextCopyFunction · 0.64
TestRaceContextCopyFunction · 0.64
captureOutputFunction · 0.64