mgo.v2 cannot unescape password in URL

如果你是使用这个种方式连接的话

mgo.DialWithTimeout("", this.timeout)

mgo 连接数据库的时候 如果密码使用了 @ 符号时候回报这个错误

cannot unescape password in URL

这个时候你可以发现 mgo.v2 还有另外一种了连接方式

this.session, err = mgo.DialWithInfo(&mgo.DialInfo{
		Addrs:    []string{this.dbcfg.getUrl()},
		Direct:   false,
		Timeout:  this.timeout,
		FailFast: false,
		Database: this.dbcfg.DbName,
		//ReplicaSetName: "",
		//Source: "",
		//Service:        "",
		//ServiceHost:    "",
		//Mechanism:      "",
		Username:   this.dbcfg.DbUser,
		Password:   this.dbcfg.DbPass,
		PoolLimit:  50, // 10M * 50
		DialServer: nil,
		Dial:       nil,
	})

其实 DialWithTimeout 这种连接方式 也是 也是他们解析第一个参数 将其变为 DialInfo 这个结构体
上面那个问题是 在解析字符转的时候出现的问题.

猜你喜欢

转载自www.cnblogs.com/vkerL/p/12725702.html
今日推荐