From f48503f2b67bb2cbbfee30bd3605f074d22832c2 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 7 Jul 2020 08:19:51 +0200 Subject: [PATCH] Container: add WithContainer helper --- middleware/container/service_container.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/middleware/container/service_container.go b/middleware/container/service_container.go index f970030..5ce9b34 100644 --- a/middleware/container/service_container.go +++ b/middleware/container/service_container.go @@ -41,3 +41,9 @@ func Must(ctx context.Context) *service.Container { func ServiceContainer(container *service.Container) goweb.Middleware { return middleware.WithValue(KeyServiceContainer, container) } + +// WithContainer returns a new context.Context with the given *service.Container +// attached. +func WithContainer(ctx context.Context, container *service.Container) context.Context { + return context.WithValue(ctx, KeyServiceContainer, container) +}