|
|
@@ -8,15 +8,15 @@ import (
|
|
8
|
8
|
// MongoDBConfig MongoDB客户端配置
|
|
9
|
9
|
type MongoDBConfig struct {
|
|
10
|
10
|
BaseConfig
|
|
11
|
|
- URI string `yaml:"uri"` // MongoDB连接URI,如:"mongodb://localhost:27017"
|
|
12
|
|
- Database string `yaml:"database"` // 默认数据库名
|
|
13
|
|
- Username string `yaml:"username"` // 用户名(可选)
|
|
14
|
|
- Password string `yaml:"password"` // 密码(可选)
|
|
15
|
|
- AuthSource string `yaml:"authSource"` // 认证数据库,默认:"admin"
|
|
16
|
|
- MaxPoolSize uint64 `yaml:"maxPoolSize"` // 最大连接池大小
|
|
17
|
|
- MinPoolSize uint64 `yaml:"minPoolSize"` // 最小连接池大小
|
|
18
|
|
- SSL bool `yaml:"ssl"` // 是否使用SSL连接
|
|
19
|
|
- Timeout time.Duration `yaml:"timeout"` // 连接超时时间(毫秒)
|
|
|
11
|
+ URI string `yaml:"uri"` // MongoDB连接URI,如:"mongodb://localhost:27017"
|
|
|
12
|
+ Database string `yaml:"database"` // 默认数据库名
|
|
|
13
|
+ Username string `yaml:"username"` // 用户名(可选)
|
|
|
14
|
+ Password string `yaml:"password"` // 密码(可选)
|
|
|
15
|
+ AuthSource string `yaml:"authSource"` // 认证数据库,默认:"admin"
|
|
|
16
|
+ MaxPoolSize uint64 `yaml:"maxPoolSize"` // 最大连接池大小
|
|
|
17
|
+ MinPoolSize uint64 `yaml:"minPoolSize"` // 最小连接池大小
|
|
|
18
|
+ SSL bool `yaml:"ssl"` // 是否使用SSL连接
|
|
|
19
|
+ Timeout int `yaml:"timeout"` // 连接超时时间,单位:秒
|
|
20
|
20
|
}
|
|
21
|
21
|
|
|
22
|
22
|
// NewMongoDBConfig 创建MongoDB配置实例
|
|
|
@@ -34,6 +34,10 @@ func (c *MongoDBConfig) SetDefaults() {
|
|
34
|
34
|
c.Timeout = 30
|
|
35
|
35
|
}
|
|
36
|
36
|
|
|
|
37
|
+func (c *MongoDBConfig) GetTimeout() time.Duration {
|
|
|
38
|
+ return time.Duration(c.Timeout) * time.Second
|
|
|
39
|
+}
|
|
|
40
|
+
|
|
37
|
41
|
// Load 从YAML数据加载配置
|
|
38
|
42
|
func (c *MongoDBConfig) Load(data map[string]interface{}) error {
|
|
39
|
43
|
return c.LoadFromYAML(data, c)
|