Files
cgrates/config/datadbcfg.go
2018-10-05 14:40:42 +03:00

70 lines
1.8 KiB
Go

/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package config
import (
"strconv"
"github.com/cgrates/cgrates/utils"
)
// DataDbCfg Database config
type DataDbCfg struct {
DataDbType string
DataDbHost string
DataDbPort string
DataDbName string
DataDbUser string
DataDbPass string
DataDbSentinelName string
}
//loadFromJsonCfg loads Database config from JsonCfg
func (dbcfg *DataDbCfg) loadFromJsonCfg(jsnDbCfg *DbJsonCfg) (err error) {
if jsnDbCfg == nil {
return nil
}
if jsnDbCfg.Db_type != nil {
dbcfg.DataDbType = *jsnDbCfg.Db_type
}
if jsnDbCfg.Db_host != nil {
dbcfg.DataDbHost = *jsnDbCfg.Db_host
}
if jsnDbCfg.Db_port != nil {
port := strconv.Itoa(*jsnDbCfg.Db_port)
if port == "-1" {
port = utils.MetaDynamic
}
dbcfg.DataDbPort = NewDbDefaults().DBPort(*jsnDbCfg.Db_type, port)
}
if jsnDbCfg.Db_name != nil {
dbcfg.DataDbName = *jsnDbCfg.Db_name
}
if jsnDbCfg.Db_user != nil {
dbcfg.DataDbUser = *jsnDbCfg.Db_user
}
if jsnDbCfg.Db_password != nil {
dbcfg.DataDbPass = *jsnDbCfg.Db_password
}
if jsnDbCfg.Redis_sentinel != nil {
dbcfg.DataDbSentinelName = *jsnDbCfg.Redis_sentinel
}
return nil
}