newRequestID returns a short, URL-safe, prefixed request id. crypto/rand is used so ids aren't guessable; on the astronomically unlikely read failure we fall back to a fixed sentinel rather than panicking a request.
()
| 25 | // is used so ids aren't guessable; on the astronomically unlikely read |
| 26 | // failure we fall back to a fixed sentinel rather than panicking a request. |
| 27 | func newRequestID() string { |
| 28 | b := make([]byte, 12) |
| 29 | if _, err := rand.Read(b); err != nil { |
| 30 | return "req_unknown" |
| 31 | } |
| 32 | return "req_" + hex.EncodeToString(b) |
| 33 | } |
| 34 | |
| 35 | // RequestIDFromContext returns the request id stamped by the requestID |
| 36 | // middleware, or "" if none is present. |