1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
url.go 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
package elasticsearch
import (
"fmt"
"net/url"
"strings"
)
func addToURL(url, path, pipeline string, params map[string]string) string {
if strings.HasSuffix(url, "/") && strings.HasPrefix(path, "/") {
url = strings.TrimSuffix(url, "/")
}
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()
}
// Create path out of index, docType and id that is used for querying Elasticsearch
func makePath(index string, docType string, id string) (string, error) {
var path string
if len(docType) > 0 {
if len(id) > 0 {
path = fmt.Sprintf("/%s/%s/%s", index, docType, id)
} else {
path = fmt.Sprintf("/%s/%s", index, docType)
}
} else {
if len(id) > 0 {
if len(index) > 0 {
path = fmt.Sprintf("/%s/%s", index, id)
} else {
path = fmt.Sprintf("/%s", id)
}
} else {
path = fmt.Sprintf("/%s", index)
}
}
return path, nil
}
// TODO: make this reusable. Same definition in elasticsearch monitoring module
func parseProxyURL(raw string) (*url.URL, error) {
if raw == "" {
return nil, nil
}
url, err := url.Parse(raw)
if err == nil && strings.HasPrefix(url.Scheme, "http") {
return url, err
}
// Proxy was bogus. Try prepending "http://" to it and
// see if that parses correctly.
return url.Parse("http://" + raw)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.1.3

搜索帮助