代码拉取完成,页面将自动刷新
package internal
import (
"fmt"
"os"
)
const (
// ElasticsearchDefaultHost is the default host for elasticsearch.
ElasticsearchDefaultHost = "localhost"
// ElasticsearchDefaultPort is the default port for elasticsearch.
ElasticsearchDefaultPort = "9200"
)
// TestLogger is used to report fatal errors to the testing framework.
type TestLogger interface {
Fatal(args ...interface{})
}
// Connectable defines the minimum interface required to initialize a connected
// client.
type Connectable interface {
Connect() error
}
// InitClient initializes a new client if the no error value from creating the
// client instance is reported.
// The test logger will be used if an error is found.
func InitClient(t TestLogger, client Connectable, err error) {
if err == nil {
err = client.Connect()
}
if err != nil {
t.Fatal(err)
panic(err) // panic in case TestLogger did not stop test
}
}
// GetEsHost returns the Elasticsearch testing host.
func GetEsHost() string {
return getEnv("ES_HOST", ElasticsearchDefaultHost)
}
// GetEsPort returns the Elasticsearch testing port.
func GetEsPort() string {
return getEnv("ES_PORT", ElasticsearchDefaultPort)
}
// GetURL return the Elasticsearch testing URL.
func GetURL() string {
return fmt.Sprintf("http://%v:%v", GetEsHost(), GetEsPort())
}
// GetUser returns the Elasticsearch testing user.
func GetUser() string { return getEnv("ES_USER", "") }
// GetPass returns the Elasticsearch testing user's password.
func GetPass() string { return getEnv("ES_PASS", "") }
func getEnv(name, def string) string {
if v := os.Getenv(name); len(v) > 0 {
return v
}
return def
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。