From 8aa660046f4659ee0b748d7bda26e30e55ddb09f Mon Sep 17 00:00:00 2001 From: jayven Date: Mon, 17 Sep 2018 09:11:09 +0800 Subject: [PATCH] Add hlog.IDFromCtx --- hlog/hlog.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hlog/hlog.go b/hlog/hlog.go index 2026214..f7c3a5a 100644 --- a/hlog/hlog.go +++ b/hlog/hlog.go @@ -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 }