package utils import ( "github.com/olivere/elastic/v7" "log" "os" ) // EsClient es客户端 var EsClient *elastic.Client func initEs() { var logInfo *log.Logger if RunMode == `debug` { logInfo = log.New(os.Stderr, "", log.LstdFlags) } clientOptionFuncList := []elastic.ClientOptionFunc{ elastic.SetURL(ES_URL), elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD), elastic.SetSniff(false), } if logInfo != nil { clientOptionFuncList = append(clientOptionFuncList, elastic.SetTraceLog(logInfo)) } client, err := elastic.NewClient( clientOptionFuncList..., ) EsClient = client if err != nil { panic("ElasticSearch连接失败,err:" + err.Error()) //go alarm_msg.SendAlarmMsg("ElasticSearch连接失败", 2) } return }