1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
testing.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
package elasticsearch
import (
"os"
"time"
"github.com/elastic/beats/libbeat/outputs/outil"
)
const ElasticsearchDefaultHost = "localhost"
const ElasticsearchDefaultPort = "9200"
func GetEsPort() string {
port := os.Getenv("ES_PORT")
if len(port) == 0 {
port = ElasticsearchDefaultPort
}
return port
}
// Returns
func GetEsHost() string {
host := os.Getenv("ES_HOST")
if len(host) == 0 {
host = ElasticsearchDefaultHost
}
return host
}
func GetTestingElasticsearch() *Client {
var address = "http://" + GetEsHost() + ":" + GetEsPort()
username := os.Getenv("ES_USER")
pass := os.Getenv("ES_PASS")
client := newTestClientAuth(address, username, pass)
// Load version number
client.Connect(3 * time.Second)
return client
}
func newTestClientAuth(url, user, pass string) *Client {
client, err := NewClient(ClientSettings{
URL: url,
Index: outil.MakeSelector(),
Username: user,
Password: pass,
Timeout: 60 * time.Second,
CompressionLevel: 3,
}, nil)
if err != nil {
panic(err)
}
return client
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.6.13

搜索帮助