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
1 changed files with 6 additions and 1 deletions

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
}