From 8079962be83b5c0e8f11b848f31c85a92ef16917 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 21 Oct 2022 15:08:26 +0200 Subject: [PATCH] src/api/log_params.go: Adding Combine() --- src/api/log_params.go | 6 ++++++ src/api/log_params_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/api/log_params.go b/src/api/log_params.go index d175d74..01961fa 100644 --- a/src/api/log_params.go +++ b/src/api/log_params.go @@ -6,3 +6,9 @@ type LogParams []interface{} func (p *LogParams) Add(field string, value interface{}) { *p = append(*p, field, value) } + +// Syntactic sugar for append(p, other...) +// Returns a new instance of LogParams with all values from both p and other +func (p LogParams) Combine(other LogParams) LogParams { + return append(p, other...) +} diff --git a/src/api/log_params_test.go b/src/api/log_params_test.go index 8291f20..dc91cbf 100644 --- a/src/api/log_params_test.go +++ b/src/api/log_params_test.go @@ -32,3 +32,19 @@ func TestLogParams(t *testing.T) { assert.ElementsMatch(t, expected, p) } + +func TestLogParamsCombine(t *testing.T) { + + a := LogParams{"one",1,"string1","str1"} + + b := LogParams{"two",2,"string2","str2"} + + expected := LogParams{ + "one",1, + "string1","str1", + "two",2, + "string2","str2", + } + + assert.Equal(t, expected, a.Combine(b)) +} \ No newline at end of file