|
|
@@ -43,12 +43,21 @@ type MqConfig struct {
|
|
|
Exchange string
|
|
|
}
|
|
|
|
|
|
+type MongoDBConfig struct {
|
|
|
+ Hostname string
|
|
|
+ Port int
|
|
|
+ DBName string
|
|
|
+ Username string
|
|
|
+ Password string
|
|
|
+}
|
|
|
+
|
|
|
type ServiceConfig struct {
|
|
|
- WebCfg WebConfig
|
|
|
- LogCfg LogConfig
|
|
|
- DbCfg DbConfig
|
|
|
- RedisCfg RedisConfig
|
|
|
- MqCfg MqConfig
|
|
|
+ WebCfg WebConfig
|
|
|
+ LogCfg LogConfig
|
|
|
+ DbCfg DbConfig
|
|
|
+ RedisCfg RedisConfig
|
|
|
+ MqCfg MqConfig
|
|
|
+ MongoDBCfg MongoDBConfig
|
|
|
}
|
|
|
|
|
|
func (c *ServiceConfig) Init(path string) error {
|
|
|
@@ -235,6 +244,49 @@ func (c *ServiceConfig) Init(path string) error {
|
|
|
SerCfg.MqCfg.Exchange = exchange.SelectAttrValue("value", "entry")
|
|
|
}
|
|
|
|
|
|
+ // MongoDB配置
|
|
|
+ mongodbsettings := root.SelectElements("MongoDBSetting")
|
|
|
+ for _, setting := range mongodbsettings {
|
|
|
+ // 主机地址
|
|
|
+ hostname := setting.SelectElement("Hostname")
|
|
|
+ if hostname == nil {
|
|
|
+ return errors.New("read mongondb hostname failed")
|
|
|
+ }
|
|
|
+ SerCfg.MongoDBCfg.Hostname = hostname.SelectAttrValue("value", "")
|
|
|
+
|
|
|
+ // 端口
|
|
|
+ port := setting.SelectElement("Port")
|
|
|
+ if port == nil {
|
|
|
+ return errors.New("read mongondb port failed")
|
|
|
+ }
|
|
|
+ ret, err := strconv.ParseUint(port.SelectAttrValue("value", "5025"), 10, 32)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("read mongondb port failed")
|
|
|
+ }
|
|
|
+ SerCfg.MongoDBCfg.Port = int(ret)
|
|
|
+
|
|
|
+ // 数据库名
|
|
|
+ dbname := setting.SelectElement("DBName")
|
|
|
+ if dbname == nil {
|
|
|
+ return errors.New("read mongondb dbname failed")
|
|
|
+ }
|
|
|
+ SerCfg.MongoDBCfg.DBName = dbname.SelectAttrValue("value", "")
|
|
|
+
|
|
|
+ // 用户名
|
|
|
+ username := setting.SelectElement("Username")
|
|
|
+ if username == nil {
|
|
|
+ return errors.New("read mongondb username failed")
|
|
|
+ }
|
|
|
+ SerCfg.MongoDBCfg.Username = username.SelectAttrValue("value", "")
|
|
|
+
|
|
|
+ // 密码
|
|
|
+ password := setting.SelectElement("Password")
|
|
|
+ if password == nil {
|
|
|
+ return errors.New("read mongondb password failed")
|
|
|
+ }
|
|
|
+ SerCfg.MongoDBCfg.Password = password.SelectAttrValue("value", "")
|
|
|
+ }
|
|
|
+
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -288,3 +340,23 @@ func (c *ServiceConfig) GetRedisConnNum() int {
|
|
|
func (c *ServiceConfig) GetRedisTimeout() int {
|
|
|
return SerCfg.RedisCfg.TimeOut
|
|
|
}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetMongoDBHostname() string {
|
|
|
+ return SerCfg.MongoDBCfg.Hostname
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetMongoDBPort() int {
|
|
|
+ return SerCfg.MongoDBCfg.Port
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetMongoDBDBName() string {
|
|
|
+ return SerCfg.MongoDBCfg.DBName
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetMongoDBUsername() string {
|
|
|
+ return SerCfg.MongoDBCfg.Username
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetMongoDBPassword() string {
|
|
|
+ return SerCfg.MongoDBCfg.Password
|
|
|
+}
|