forked from mbrancato/beats-output-http
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathurl.go
More file actions
32 lines (24 loc) · 682 Bytes
/
Copy pathurl.go
File metadata and controls
32 lines (24 loc) · 682 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 http
// Taken from https://github.com/elastic/beats/blob/master/libbeat/outputs/elasticsearch/url.go
// with minor changes
import (
"net/url"
"strings"
)
func makeURL(url, path, pipeline string, params map[string]string) string {
if len(params) == 0 && pipeline == "" {
return url + path
}
return strings.Join([]string{url, path, "?", urlEncode(pipeline, params),}, "")
}
// Encode parameters in url
func urlEncode(pipeline string, params map[string]string) string {
values := url.Values{}
for key, val := range params {
values.Add(key, string(val))
}
if pipeline != "" {
values.Add("pipeline", pipeline)
}
return values.Encode()
}