-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add two new functions for dynamic headers (#31)
* add two new functions for dynamic headers * use named return values * make function specific to url-encoded forms and allow for selecting arbitrary elements from the json * Minor (#32) * clean up isJSON funcs * use external lib for json value retrieval * simplify compacting json * update dependencies * handle empty string field and update readme * fix whitespace in readme * fix json array syntax * handle non-json response bodies Co-authored-by: Tony Li <[email protected]>
- Loading branch information
1 parent
433c953
commit 4ddc601
Showing
24 changed files
with
5,204 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package functions | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// Concat concatenates the args into a single string, substituting previously defined headers if available. | ||
func Concat(existingHeaders map[string]string, args []string) (string, error) { | ||
var buffer strings.Builder | ||
|
||
for _, arg := range args { | ||
if value, ok := existingHeaders[arg]; ok { | ||
buffer.WriteString(value) | ||
} else { | ||
buffer.WriteString(arg) | ||
} | ||
} | ||
|
||
return buffer.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package functions | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestConcat(t *testing.T) { | ||
var tests = []struct { | ||
existingHeaders map[string]string | ||
args []string | ||
expected string | ||
}{ | ||
{ | ||
map[string]string{}, | ||
[]string{""}, | ||
"", | ||
}, | ||
{ | ||
map[string]string{}, | ||
[]string{"my string"}, | ||
"my string", | ||
}, | ||
{ | ||
map[string]string{ | ||
"x-previous-header": "123", | ||
}, | ||
[]string{""}, | ||
"", | ||
}, | ||
{ | ||
map[string]string{ | ||
"x-previous-header": "123", | ||
}, | ||
[]string{"x-previous-header"}, | ||
"123", | ||
}, | ||
{ | ||
map[string]string{ | ||
"x-previous-header": "123", | ||
}, | ||
[]string{"x-previous-header", "my string"}, | ||
"123my string", | ||
}, | ||
{ | ||
map[string]string{ | ||
"x-previous-header1": "123", | ||
"x-previous-header2": "456", | ||
}, | ||
[]string{"x-previous-header1", "my string", "x-previous-header2"}, | ||
"123my string456", | ||
}, | ||
{ | ||
map[string]string{ | ||
"x-previous-header1": "123", | ||
}, | ||
[]string{"x-previous-header2", "my string"}, | ||
"x-previous-header2my string", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
actual, _ := Concat(tc.existingHeaders, tc.args) | ||
if actual != tc.expected { | ||
t.Errorf("Concat(%v, %v): expected %v, actual %v", tc.existingHeaders, tc.args, tc.expected, actual) | ||
} | ||
} | ||
} |
Oops, something went wrong.