Skip to content

Commit

Permalink
feat: add support for QueryParam
Browse files Browse the repository at this point in the history
  • Loading branch information
synack-evan authored and rbretecher committed Sep 20, 2022
1 parent fb148ca commit 093c434
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
12 changes: 4 additions & 8 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,14 @@ func (suite *CollectionTestSuite) TestSimpleGETItem() {

defer file.Close()

m1 := map[string]interface{}{"key": "param1", "value": "value1"}
m2 := map[string]interface{}{"key": "param2", "value": "value2"}

var arrMaps []map[string]interface{}
arrMaps = append(arrMaps, m1)
arrMaps = append(arrMaps, m2)

pURL := URL{
Raw: "https://test.com?a=3",
Protocol: "https",
Host: []string{"test", "com"},
Query: arrMaps,
Query: []*QueryParam{
{Key: "param1", Value: "value1"},
{Key: "param2", Value: "value2"},
},
}

headers := []*Header{}
Expand Down
22 changes: 14 additions & 8 deletions url.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ import (
// Raw contains the complete URL.
type URL struct {
version version
Raw string `json:"raw"`
Protocol string `json:"protocol,omitempty"`
Host []string `json:"host,omitempty"`
Path []string `json:"path,omitempty"`
Port string `json:"port,omitempty"`
Query interface{} `json:"query,omitempty"`
Hash string `json:"hash,omitempty"`
Variables []*Variable `json:"variable,omitempty" mapstructure:"variable"`
Raw string `json:"raw"`
Protocol string `json:"protocol,omitempty"`
Host []string `json:"host,omitempty"`
Path []string `json:"path,omitempty"`
Port string `json:"port,omitempty"`
Query []*QueryParam `json:"query,omitempty"`
Hash string `json:"hash,omitempty"`
Variables []*Variable `json:"variable,omitempty" mapstructure:"variable"`
}

// mURL is used for marshalling/unmarshalling.
type mURL URL

type QueryParam struct {
Key string `json:"key"`
Value string `json:"value"`
Description *string `json:"description"`
}

// String returns the raw version of the URL.
func (u URL) String() string {
return u.Raw
Expand Down
14 changes: 14 additions & 0 deletions url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ func TestURLUnmarshalJSON(t *testing.T) {
},
nil,
},
{
"Successfully unmarshalling an URL with query as a struct",
[]byte("{\"raw\":\"http://www.google.fr\",\"query\":[{\"key\":\"param1\",\"value\":\"an-awesome-value\"}]}"),
URL{
Raw: "http://www.google.fr",
Query: []*QueryParam{
{
Key: "param1",
Value: "an-awesome-value",
},
},
},
nil,
},
{
"Failed to unmarshal an URL because of an unsupported type",
[]byte("not-a-valid-url"),
Expand Down

0 comments on commit 093c434

Please sign in to comment.