123456789101112131415161718192021222324252627 |
- package utils
- import (
- "github.com/olivere/elastic/v7"
- "time"
- )
- var Client *elastic.Client
- const (
- ES_URL = "http://es-cn-nif227b580019rgw6.public.elasticsearch.aliyuncs.com:9200" //<1>
- ES_USERNAME = "elastic" //<2>
- ES_PASSWORD = "hongze@2021" //<3>
- )
- func init() {
- client, err := elastic.NewClient(
- elastic.SetURL(ES_URL),
- elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
- elastic.SetSniff(false))
- Client = client
- if err != nil {
- go SendAlarmMsg("ElasticSearch连接失败", 2)
- go SendEmail("ElasticSearch连接失败"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), EmailSendToUsers)
- }
- return
- }
|