Browse Source

添加用户密码

wcc 2 years ago
parent
commit
4289580ee0
1 changed files with 3 additions and 1 deletions
  1. 3 1
      elastic/elasticSim.go

+ 3 - 1
elastic/elasticSim.go

@@ -22,6 +22,8 @@ type Elastic struct {
 	lastTime     int64
 	lastTimeLock sync.Mutex
 	ntimeout     int
+	Username     string
+	Password     string
 }
 
 func (e *Elastic) InitElasticSize() {
@@ -30,7 +32,7 @@ func (e *Elastic) InitElasticSize() {
 		e.Addrs = append(e.Addrs, s)
 	}
 	for i := 0; i < e.I_size; 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
 	}
 }