|
@@ -127,6 +127,8 @@ type MongodbSim struct {
|
|
|
Ctx context.Context
|
|
|
ShortCtx context.Context
|
|
|
pool chan bool
|
|
|
+ UserName string
|
|
|
+ Password string
|
|
|
}
|
|
|
|
|
|
func (m *MongodbSim) GetMgoConn() *MgoSess {
|
|
@@ -147,6 +149,13 @@ func (m *MongodbSim) InitPool() {
|
|
|
opts.SetConnectTimeout(3 * time.Second)
|
|
|
opts.ApplyURI("mongodb://" + m.MongodbAddr)
|
|
|
opts.SetMaxPoolSize(uint64(m.Size))
|
|
|
+ if m.UserName != "" && m.Password != "" {
|
|
|
+ cre := options.Credential{
|
|
|
+ Username: m.UserName,
|
|
|
+ Password: m.Password,
|
|
|
+ }
|
|
|
+ opts.SetAuth(cre)
|
|
|
+ }
|
|
|
m.pool = make(chan bool, m.Size)
|
|
|
opts.SetMaxConnIdleTime(2 * time.Hour)
|
|
|
m.Ctx, _ = context.WithTimeout(context.Background(), 99999*time.Hour)
|