package main import ( "context" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) type Mgo struct { Uri string PoolSize uint64 mgoEn *mongo.Client } func InitMgoEn(uri string, poolSize uint64,username_password ... string) (*Mgo, error) { //fengweiqiang fwq@123123 m := Mgo{} m.Uri = uri if poolSize == 0 { m.PoolSize = 100 } //fengweiqiang/fwq@123123 options_client := options.Client(). ApplyURI(uri).SetMaxPoolSize(m.PoolSize) if len(username_password)==2{ options_client = options_client.SetAuth(options.Credential{Username: username_password[0], Password: username_password[1]}) } client, err := mongo.Connect(context.Background(), options_client) if err != nil { return nil, err } else { m.mgoEn = client return &m, nil } } func (m *Mgo) GetCon() *mongo.Client { if m.mgoEn != nil { return m.mgoEn } else { return nil } } //var zwjeReg *regexp.Regexp = regexp.MustCompile(`([〇零点壹贰叁肆伍陆柒捌玖拾百佰千仟万萬亿億元圆角分整正]{4,40})`)