1
0
mirror of https://github.com/rs/zerolog synced 2026-06-08 17:13:30 +00:00

Add hlog.IDFromCtx

This commit is contained in:
jayven
2018-09-17 09:11:09 +08:00
committed by Olivier Poitrey
parent 470da8d0bb
commit 8aa660046f
+6 -1
View File
@@ -129,7 +129,12 @@ func IDFromRequest(r *http.Request) (id xid.ID, ok bool) {
if r == nil {
return
}
id, ok = r.Context().Value(idKey{}).(xid.ID)
return IDFromCtx(r.Context())
}
// IDFromCtx returns the unique id associated to the context if any.
func IDFromCtx(ctx context.Context) (id xid.ID, ok bool) {
id, ok = ctx.Value(idKey{}).(xid.ID)
return
}