func GetMongoConnFromConfig(container string) string { if !conf.Exists(container) { panic("Container for mongo configuration not found") } username := conf.String(container+".username", "") password := conf.String(container+".password", "") host := conf.String(container+".host", "") port := conf.String(container+".port", "") db := conf.String(container+".db", "") replicas := conf.String(container+".replicas", "") options := conf.String(container+".options", "") if port != "" { port = ":" + port } if replicas != "" { replicas = "," + replicas } if options != "" { options = "?" + options } auth := "" if username != "" || password != "" { auth = username + ":" + password + "@" } return fmt.Sprintf("mongodb://%s%s%s%s/%s%s", auth, host, port, replicas, db, options, ) }
func initMongo() { lookup := "database.mongo" if conf.Exists(lookup) { connMongo = GetMongoConnFromConfig(lookup) dbMongo = conf.String("database.mongo.db", "") } }
// validate the container string func validateContainer(container string) (db string, err error) { if conf.Exists(container) == false { err = errors.New("mongo configuration missing") return } db = container return }
func initSlaves() { lookup := "database.slaves" if conf.Exists(lookup) { slaves := conf.StringSlice(lookup, []string{}) connMySqlRead = make([]string, len(slaves)) for i, container := range slaves { connMySqlRead[i] = getMySqlConnString(container) } } }
func getMySqlConnString(container string) string { if !conf.Exists(container) { panic("Container for mysql configuration not found") } username := conf.String(container+".username", "") password := conf.String(container+".password", "") host := conf.String(container+".host", "") port := conf.String(container+".port", "") db := conf.String(container+".db", "") timezone := conf.String(container+".timezone", "") return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true&loc=%s", username, password, host, port, db, url.QueryEscape(timezone), ) }
func initMaster() { lookup := "database.master" if conf.Exists(lookup) { connMySqlWrite = getMySqlConnString(lookup) } }
func initMySqlMaster() { lookup := "database.master" if conf.Exists(lookup) { connMySqlWrite = GetMySqlConnFromConfig(lookup) } }