Handler returns an Iris handler to be served in a route of an Iris application. Accepts the neffos websocket server as its first input argument and optionally an Iris-specific `IDGenerator` as its second one. This SHOULD be the last handler in the route's chain as it hijacks the connection and the
(s *neffos.Server, idGenerator ...IDGenerator)
| 154 | // |
| 155 | // This SHOULD be the last handler in the route's chain as it hijacks the connection and the context. |
| 156 | func Handler(s *neffos.Server, idGenerator ...IDGenerator) context.Handler { |
| 157 | idGen := DefaultIDGenerator |
| 158 | if len(idGenerator) > 0 { |
| 159 | idGen = idGenerator[0] |
| 160 | } |
| 161 | |
| 162 | if cb := s.OnDisconnect; cb != nil { |
| 163 | s.OnDisconnect = func(c *neffos.Conn) { |
| 164 | cb(c) |
| 165 | manualReleaseWithoutResp(GetContext(c)) |
| 166 | } |
| 167 | } else { |
| 168 | s.OnDisconnect = func(c *neffos.Conn) { |
| 169 | manualReleaseWithoutResp(GetContext(c)) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return func(ctx *context.Context) { |
| 174 | if ctx.IsStopped() { |
| 175 | // let the framework release it as always; |
| 176 | // socket was not created so disconnect event will not called and the |
| 177 | // DisablePoolRelease was not even called yet. |
| 178 | return |
| 179 | } |
| 180 | |
| 181 | Upgrade(ctx, idGen, s) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // Upgrade upgrades the request and returns a new websocket Conn. |
| 186 | // Use `Handler` for higher-level implementation instead. |
no test coverage detected
searching dependent graphs…