-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueries.go
More file actions
32 lines (28 loc) · 663 Bytes
/
queries.go
File metadata and controls
32 lines (28 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package paystack
import (
"fmt"
"strings"
)
// Query helps represent key value pairs used in url query parametes
type Query struct {
Key string
Value string
}
// WithQuery lets you create a Query from key value pairs
func WithQuery(key string, value string) Query {
return Query{
Key: key,
Value: value,
}
}
// AddQueryParamsToUrl lets you add query parameters to a url
func AddQueryParamsToUrl(url string, queries ...Query) string {
for _, query := range queries {
if strings.Contains(url, "?") {
url += fmt.Sprintf("&%s=%s", query.Key, query.Value)
} else {
url += fmt.Sprintf("?%s=%s", query.Key, query.Value)
}
}
return url
}