Migration
This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs.
Contact me
internal/core/ctxutil.go
main
· 373 B · 18 lines
raw
| 1 | package core |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | type contexter interface{ Ctx() context.Context } |
| 10 | |
| 11 | type reqCtx struct{ c context.Context } |
| 12 | |
| 13 | func (r reqCtx) Ctx() context.Context { return r.c } |
| 14 | |
| 15 | func contextWithTimeout(r *http.Request, d time.Duration) (contexter, context.CancelFunc) { |
| 16 | c, cancel := context.WithTimeout(r.Context(), d) |
| 17 | return reqCtx{c}, cancel |
| 18 | } |