From e26e703a9e17b76843f19c38dc2ff3aab00f0a6e Mon Sep 17 00:00:00 2001 From: Brad Moylan Date: Thu, 17 Nov 2022 16:03:17 -0800 Subject: [PATCH 1/2] improvement: New*ParamStorer and ContextWith*Params accept variadic map arguments --- paramstorer.go | 20 ++++++++++++++++---- paramstorer_context.go | 8 ++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/paramstorer.go b/paramstorer.go index 77598af..5251c57 100644 --- a/paramstorer.go +++ b/paramstorer.go @@ -25,8 +25,14 @@ func NewParamStorer(paramStorers ...ParamStorer) ParamStorer { } // NewSafeParamStorer returns a new ParamStorer that stores the provided parameters as SafeParams. -func NewSafeParamStorer(safeParams map[string]interface{}) ParamStorer { - return NewSafeAndUnsafeParamStorer(safeParams, nil) +func NewSafeParamStorer(safeParams ...map[string]interface{}) ParamStorer { + storer := &mapParamStorer{} + for _, p := range safeParams { + for k, v := range p { + storer.putSafeParam(k, v) + } + } + return storer } // NewSafeParam returns a new ParamStorer that stores a single safe parameter. @@ -35,8 +41,14 @@ func NewSafeParam(key string, value interface{}) ParamStorer { } // NewUnsafeParamStorer returns a new ParamStorer that stores the provided parameters as UnsafeParams. -func NewUnsafeParamStorer(unsafeParams map[string]interface{}) ParamStorer { - return NewSafeAndUnsafeParamStorer(nil, unsafeParams) +func NewUnsafeParamStorer(unsafeParams ...map[string]interface{}) ParamStorer { + storer := &mapParamStorer{} + for _, p := range unsafeParams { + for k, v := range p { + storer.putUnsafeParam(k, v) + } + } + return storer } // NewUnsafeParam returns a new ParamStorer that stores a single unsafe parameter. diff --git a/paramstorer_context.go b/paramstorer_context.go index e376bf4..5e1f1bb 100644 --- a/paramstorer_context.go +++ b/paramstorer_context.go @@ -25,8 +25,8 @@ func ContextWithSafeParam(ctx context.Context, key string, value interface{}) co // ContextWithSafeParams returns a copy of the provided context that contains the provided safe parameters. If the // provided context already has safe/unsafe params, the newly returned context will contain the result of merging the // previous parameters with the provided parameters. -func ContextWithSafeParams(ctx context.Context, safeParams map[string]interface{}) context.Context { - return ContextWithParamStorers(ctx, NewSafeParamStorer(safeParams)) +func ContextWithSafeParams(ctx context.Context, safeParams ...map[string]interface{}) context.Context { + return ContextWithParamStorers(ctx, NewSafeParamStorer(safeParams...)) } // ContextWithUnsafeParam returns a copy of the provided context that contains the provided unsafe parameter. If the @@ -39,8 +39,8 @@ func ContextWithUnsafeParam(ctx context.Context, key string, value interface{}) // ContextWithUnsafeParams returns a copy of the provided context that contains the provided unsafe parameters. If the // provided context already has safe/unsafe params, the newly returned context will contain the result of merging the // previous parameters with the provided parameters. -func ContextWithUnsafeParams(ctx context.Context, unsafeParams map[string]interface{}) context.Context { - return ContextWithParamStorers(ctx, NewUnsafeParamStorer(unsafeParams)) +func ContextWithUnsafeParams(ctx context.Context, unsafeParams ...map[string]interface{}) context.Context { + return ContextWithParamStorers(ctx, NewUnsafeParamStorer(unsafeParams...)) } // ContextWithSafeAndUnsafeParams returns a copy of the provided context that contains the provided safe and unsafe From 1d81ba5c4e9c9753f27a399b4f215dd3655dc9ef Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Fri, 18 Nov 2022 00:03:56 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-133.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-133.v2.yml diff --git a/changelog/@unreleased/pr-133.v2.yml b/changelog/@unreleased/pr-133.v2.yml new file mode 100644 index 0000000..9b23f87 --- /dev/null +++ b/changelog/@unreleased/pr-133.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: New*ParamStorer and ContextWith*Params accept variadic map arguments + links: + - https://github.com/palantir/witchcraft-go-params/pull/133