github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/felixge/httpsnoop/wrap_generated_gteq_1.8.go (about) 1 //go:build go1.8 2 // +build go1.8 3 4 // Code generated by "httpsnoop/codegen"; DO NOT EDIT 5 6 package httpsnoop 7 8 import ( 9 "bufio" 10 "github.com/hellobchain/newcryptosm/http" 11 "io" 12 "net" 13 ) 14 15 // HeaderFunc is part of the http.ResponseWriter interface. 16 type HeaderFunc func() http.Header 17 18 // WriteHeaderFunc is part of the http.ResponseWriter interface. 19 type WriteHeaderFunc func(code int) 20 21 // WriteFunc is part of the http.ResponseWriter interface. 22 type WriteFunc func(b []byte) (int, error) 23 24 // FlushFunc is part of the http.Flusher interface. 25 type FlushFunc func() 26 27 // CloseNotifyFunc is part of the http.CloseNotifier interface. 28 type CloseNotifyFunc func() <-chan bool 29 30 // HijackFunc is part of the http.Hijacker interface. 31 type HijackFunc func() (net.Conn, *bufio.ReadWriter, error) 32 33 // ReadFromFunc is part of the io.ReaderFrom interface. 34 type ReadFromFunc func(src io.Reader) (int64, error) 35 36 // PushFunc is part of the http.Pusher interface. 37 type PushFunc func(target string, opts *http.PushOptions) error 38 39 // Hooks defines a set of method interceptors for methods included in 40 // http.ResponseWriter as well as some others. You can think of them as 41 // middleware for the function calls they target. See Wrap for more details. 42 type Hooks struct { 43 Header func(HeaderFunc) HeaderFunc 44 WriteHeader func(WriteHeaderFunc) WriteHeaderFunc 45 Write func(WriteFunc) WriteFunc 46 Flush func(FlushFunc) FlushFunc 47 CloseNotify func(CloseNotifyFunc) CloseNotifyFunc 48 Hijack func(HijackFunc) HijackFunc 49 ReadFrom func(ReadFromFunc) ReadFromFunc 50 Push func(PushFunc) PushFunc 51 } 52 53 // Wrap returns a wrapped version of w that provides the exact same interface 54 // as w. Specifically if w implements any combination of: 55 // 56 // - http.Flusher 57 // - http.CloseNotifier 58 // - http.Hijacker 59 // - io.ReaderFrom 60 // - http.Pusher 61 // 62 // The wrapped version will implement the exact same combination. If no hooks 63 // are set, the wrapped version also behaves exactly as w. Hooks targeting 64 // methods not supported by w are ignored. Any other hooks will intercept the 65 // method they target and may modify the call's arguments and/or return values. 66 // The CaptureMetrics implementation serves as a working example for how the 67 // hooks can be used. 68 func Wrap(w http.ResponseWriter, hooks Hooks) http.ResponseWriter { 69 rw := &rw{w: w, h: hooks} 70 _, i0 := w.(http.Flusher) 71 _, i1 := w.(http.CloseNotifier) 72 _, i2 := w.(http.Hijacker) 73 _, i3 := w.(io.ReaderFrom) 74 _, i4 := w.(http.Pusher) 75 switch { 76 // combination 1/32 77 case !i0 && !i1 && !i2 && !i3 && !i4: 78 return struct { 79 http.ResponseWriter 80 }{rw} 81 // combination 2/32 82 case !i0 && !i1 && !i2 && !i3 && i4: 83 return struct { 84 http.ResponseWriter 85 http.Pusher 86 }{rw, rw} 87 // combination 3/32 88 case !i0 && !i1 && !i2 && i3 && !i4: 89 return struct { 90 http.ResponseWriter 91 io.ReaderFrom 92 }{rw, rw} 93 // combination 4/32 94 case !i0 && !i1 && !i2 && i3 && i4: 95 return struct { 96 http.ResponseWriter 97 io.ReaderFrom 98 http.Pusher 99 }{rw, rw, rw} 100 // combination 5/32 101 case !i0 && !i1 && i2 && !i3 && !i4: 102 return struct { 103 http.ResponseWriter 104 http.Hijacker 105 }{rw, rw} 106 // combination 6/32 107 case !i0 && !i1 && i2 && !i3 && i4: 108 return struct { 109 http.ResponseWriter 110 http.Hijacker 111 http.Pusher 112 }{rw, rw, rw} 113 // combination 7/32 114 case !i0 && !i1 && i2 && i3 && !i4: 115 return struct { 116 http.ResponseWriter 117 http.Hijacker 118 io.ReaderFrom 119 }{rw, rw, rw} 120 // combination 8/32 121 case !i0 && !i1 && i2 && i3 && i4: 122 return struct { 123 http.ResponseWriter 124 http.Hijacker 125 io.ReaderFrom 126 http.Pusher 127 }{rw, rw, rw, rw} 128 // combination 9/32 129 case !i0 && i1 && !i2 && !i3 && !i4: 130 return struct { 131 http.ResponseWriter 132 http.CloseNotifier 133 }{rw, rw} 134 // combination 10/32 135 case !i0 && i1 && !i2 && !i3 && i4: 136 return struct { 137 http.ResponseWriter 138 http.CloseNotifier 139 http.Pusher 140 }{rw, rw, rw} 141 // combination 11/32 142 case !i0 && i1 && !i2 && i3 && !i4: 143 return struct { 144 http.ResponseWriter 145 http.CloseNotifier 146 io.ReaderFrom 147 }{rw, rw, rw} 148 // combination 12/32 149 case !i0 && i1 && !i2 && i3 && i4: 150 return struct { 151 http.ResponseWriter 152 http.CloseNotifier 153 io.ReaderFrom 154 http.Pusher 155 }{rw, rw, rw, rw} 156 // combination 13/32 157 case !i0 && i1 && i2 && !i3 && !i4: 158 return struct { 159 http.ResponseWriter 160 http.CloseNotifier 161 http.Hijacker 162 }{rw, rw, rw} 163 // combination 14/32 164 case !i0 && i1 && i2 && !i3 && i4: 165 return struct { 166 http.ResponseWriter 167 http.CloseNotifier 168 http.Hijacker 169 http.Pusher 170 }{rw, rw, rw, rw} 171 // combination 15/32 172 case !i0 && i1 && i2 && i3 && !i4: 173 return struct { 174 http.ResponseWriter 175 http.CloseNotifier 176 http.Hijacker 177 io.ReaderFrom 178 }{rw, rw, rw, rw} 179 // combination 16/32 180 case !i0 && i1 && i2 && i3 && i4: 181 return struct { 182 http.ResponseWriter 183 http.CloseNotifier 184 http.Hijacker 185 io.ReaderFrom 186 http.Pusher 187 }{rw, rw, rw, rw, rw} 188 // combination 17/32 189 case i0 && !i1 && !i2 && !i3 && !i4: 190 return struct { 191 http.ResponseWriter 192 http.Flusher 193 }{rw, rw} 194 // combination 18/32 195 case i0 && !i1 && !i2 && !i3 && i4: 196 return struct { 197 http.ResponseWriter 198 http.Flusher 199 http.Pusher 200 }{rw, rw, rw} 201 // combination 19/32 202 case i0 && !i1 && !i2 && i3 && !i4: 203 return struct { 204 http.ResponseWriter 205 http.Flusher 206 io.ReaderFrom 207 }{rw, rw, rw} 208 // combination 20/32 209 case i0 && !i1 && !i2 && i3 && i4: 210 return struct { 211 http.ResponseWriter 212 http.Flusher 213 io.ReaderFrom 214 http.Pusher 215 }{rw, rw, rw, rw} 216 // combination 21/32 217 case i0 && !i1 && i2 && !i3 && !i4: 218 return struct { 219 http.ResponseWriter 220 http.Flusher 221 http.Hijacker 222 }{rw, rw, rw} 223 // combination 22/32 224 case i0 && !i1 && i2 && !i3 && i4: 225 return struct { 226 http.ResponseWriter 227 http.Flusher 228 http.Hijacker 229 http.Pusher 230 }{rw, rw, rw, rw} 231 // combination 23/32 232 case i0 && !i1 && i2 && i3 && !i4: 233 return struct { 234 http.ResponseWriter 235 http.Flusher 236 http.Hijacker 237 io.ReaderFrom 238 }{rw, rw, rw, rw} 239 // combination 24/32 240 case i0 && !i1 && i2 && i3 && i4: 241 return struct { 242 http.ResponseWriter 243 http.Flusher 244 http.Hijacker 245 io.ReaderFrom 246 http.Pusher 247 }{rw, rw, rw, rw, rw} 248 // combination 25/32 249 case i0 && i1 && !i2 && !i3 && !i4: 250 return struct { 251 http.ResponseWriter 252 http.Flusher 253 http.CloseNotifier 254 }{rw, rw, rw} 255 // combination 26/32 256 case i0 && i1 && !i2 && !i3 && i4: 257 return struct { 258 http.ResponseWriter 259 http.Flusher 260 http.CloseNotifier 261 http.Pusher 262 }{rw, rw, rw, rw} 263 // combination 27/32 264 case i0 && i1 && !i2 && i3 && !i4: 265 return struct { 266 http.ResponseWriter 267 http.Flusher 268 http.CloseNotifier 269 io.ReaderFrom 270 }{rw, rw, rw, rw} 271 // combination 28/32 272 case i0 && i1 && !i2 && i3 && i4: 273 return struct { 274 http.ResponseWriter 275 http.Flusher 276 http.CloseNotifier 277 io.ReaderFrom 278 http.Pusher 279 }{rw, rw, rw, rw, rw} 280 // combination 29/32 281 case i0 && i1 && i2 && !i3 && !i4: 282 return struct { 283 http.ResponseWriter 284 http.Flusher 285 http.CloseNotifier 286 http.Hijacker 287 }{rw, rw, rw, rw} 288 // combination 30/32 289 case i0 && i1 && i2 && !i3 && i4: 290 return struct { 291 http.ResponseWriter 292 http.Flusher 293 http.CloseNotifier 294 http.Hijacker 295 http.Pusher 296 }{rw, rw, rw, rw, rw} 297 // combination 31/32 298 case i0 && i1 && i2 && i3 && !i4: 299 return struct { 300 http.ResponseWriter 301 http.Flusher 302 http.CloseNotifier 303 http.Hijacker 304 io.ReaderFrom 305 }{rw, rw, rw, rw, rw} 306 // combination 32/32 307 case i0 && i1 && i2 && i3 && i4: 308 return struct { 309 http.ResponseWriter 310 http.Flusher 311 http.CloseNotifier 312 http.Hijacker 313 io.ReaderFrom 314 http.Pusher 315 }{rw, rw, rw, rw, rw, rw} 316 } 317 panic("unreachable") 318 } 319 320 type rw struct { 321 w http.ResponseWriter 322 h Hooks 323 } 324 325 func (w *rw) Header() http.Header { 326 f := w.w.(http.ResponseWriter).Header 327 if w.h.Header != nil { 328 f = w.h.Header(f) 329 } 330 return f() 331 } 332 333 func (w *rw) WriteHeader(code int) { 334 f := w.w.(http.ResponseWriter).WriteHeader 335 if w.h.WriteHeader != nil { 336 f = w.h.WriteHeader(f) 337 } 338 f(code) 339 } 340 341 func (w *rw) Write(b []byte) (int, error) { 342 f := w.w.(http.ResponseWriter).Write 343 if w.h.Write != nil { 344 f = w.h.Write(f) 345 } 346 return f(b) 347 } 348 349 func (w *rw) Flush() { 350 f := w.w.(http.Flusher).Flush 351 if w.h.Flush != nil { 352 f = w.h.Flush(f) 353 } 354 f() 355 } 356 357 func (w *rw) CloseNotify() <-chan bool { 358 f := w.w.(http.CloseNotifier).CloseNotify 359 if w.h.CloseNotify != nil { 360 f = w.h.CloseNotify(f) 361 } 362 return f() 363 } 364 365 func (w *rw) Hijack() (net.Conn, *bufio.ReadWriter, error) { 366 f := w.w.(http.Hijacker).Hijack 367 if w.h.Hijack != nil { 368 f = w.h.Hijack(f) 369 } 370 return f() 371 } 372 373 func (w *rw) ReadFrom(src io.Reader) (int64, error) { 374 f := w.w.(io.ReaderFrom).ReadFrom 375 if w.h.ReadFrom != nil { 376 f = w.h.ReadFrom(f) 377 } 378 return f(src) 379 } 380 381 func (w *rw) Push(target string, opts *http.PushOptions) error { 382 f := w.w.(http.Pusher).Push 383 if w.h.Push != nil { 384 f = w.h.Push(f) 385 } 386 return f(target, opts) 387 }