Jianghan 2 سال پیش
والد
کامیت
6d17520127
1فایلهای تغییر یافته به همراه3 افزوده شده و 3 حذف شده
  1. 3 3
      elastic/elasticSim.go

+ 3 - 3
elastic/elasticSim.go

@@ -55,7 +55,7 @@ func (e *Elastic) GetEsConn() *es.Client {
 	case c := <-e.Pool:
 		if c == nil || !c.IsRunning() {
 			log.Println("new esclient.", len(e.Pool))
-			client, err := es.NewClient(es.SetURL(e.Addrs...),
+			client, err := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password),
 				es.SetMaxRetries(2), es.SetSniff(false))
 			if err == nil && client.IsRunning() {
 				return client
@@ -72,10 +72,10 @@ func (e *Elastic) GetEsConn() *es.Client {
 		if c > 12 {
 			e.lastTime = time.Now().Unix()
 			log.Println("add client..", len(e.Pool))
-			c, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
+			c, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
 			go func() {
 				for i := 0; i < 2; i++ {
-					client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
+					client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
 					e.Pool <- client
 				}
 			}()