From 2758b3b53c49bff72173d80858947f3bfeb4632a Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 17 May 2020 18:16:36 +0200 Subject: [PATCH] Change header syntax to equal sign To align with other key-value CLIs where the equal is more typical than colon. --- cfg/config.go | 4 ++-- cfg/config_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index bc3d28e..a96e220 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -58,11 +58,11 @@ func ParseConfig(version, commit, date string, fs *flag.FlagSet, args []string) func ConvertHeaders(headers []string, header *http.Header) { for _, hd := range headers { - arr := strings.SplitN(hd, ":", 2) + arr := strings.SplitN(hd, "=", 2) if len(arr) < 2 { log.WithFields(log.Fields{ "arg": hd, - "error": "cannot split: missing colon", + "error": "cannot split: missing equal sign", }).Warn("Could not parse header, ignoring") continue } diff --git a/cfg/config_test.go b/cfg/config_test.go index 2687ef3..c83cafc 100644 --- a/cfg/config_test.go +++ b/cfg/config_test.go @@ -42,7 +42,7 @@ func TestConvertHeaders(t *testing.T) { { name: "WhenValidEntry_ThenParse", args: args{ - headers: []string{"Authentication: Bearer "}, + headers: []string{"Authentication= Bearer "}, header: &http.Header{}, }, verify: func(header *http.Header) { @@ -52,7 +52,7 @@ func TestConvertHeaders(t *testing.T) { { name: "GivenValidEntry_WhenSpacesAroundValues_ThenTrim", args: args{ - headers: []string{" Authentication: Bearer "}, + headers: []string{" Authentication = Bearer "}, header: &http.Header{}, }, verify: func(header *http.Header) { @@ -123,20 +123,20 @@ func TestParseConfig(t *testing.T) { }, { name: "GivenHeaderFlags_WhenMultipleHeadersSpecified_ThenFillArray", - args: []string{"--symo.header", "key1:value1", "--symo.header", "KEY2: value2"}, + args: []string{"--symo.header", "key1=value1", "--symo.header", "KEY2= value2"}, verify: func(c *Configuration) { - assert.Contains(t, c.Symo.Headers, "key1:value1") - assert.Contains(t, c.Symo.Headers, "KEY2: value2") + assert.Contains(t, c.Symo.Headers, "key1=value1") + assert.Contains(t, c.Symo.Headers, "KEY2= value2") }, }, { name: "GivenHeaderEnvVar_WhenMultipleHeadersSpecified_ThenFillArray", envs: map[string]string{ - "SYMO_HEADER": "key1:value1, KEY2: value2", + "SYMO_HEADER": "key1=value1, KEY2= value2", }, verify: func(c *Configuration) { - assert.Contains(t, c.Symo.Headers, "key1:value1") - assert.Contains(t, c.Symo.Headers, " KEY2: value2") + assert.Contains(t, c.Symo.Headers, "key1=value1") + assert.Contains(t, c.Symo.Headers, " KEY2= value2") }, }, {