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.
()
| 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. |
| 122 | func (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". |
no outgoing calls