Example #1
0
File: db.go Project: tolexo/aero
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,
	)
}
Example #2
0
File: db.go Project: tolexo/aero
func initMongo() {
	lookup := "database.mongo"
	if conf.Exists(lookup) {
		connMongo = GetMongoConnFromConfig(lookup)
		dbMongo = conf.String("database.mongo.db", "")
	}
}
Example #3
0
// 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
}
Example #4
0
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)
		}
	}
}
Example #5
0
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),
	)
}
Example #6
0
func initMaster() {
	lookup := "database.master"
	if conf.Exists(lookup) {
		connMySqlWrite = getMySqlConnString(lookup)
	}
}
Example #7
0
File: db.go Project: tolexo/aero
func initMySqlMaster() {
	lookup := "database.master"
	if conf.Exists(lookup) {
		connMySqlWrite = GetMySqlConnFromConfig(lookup)
	}
}