Ejemplo n.º 1
0
func newDBConn() *mysql.Client {
	client, err := mysql.DialTCP(HOST, USER, PASSWD, DB)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	return client
}
Ejemplo n.º 2
0
func (pc *mycon) Connect(cd ...*ps.ConnData) bool {
	if len(cd) > 0 {
		pc.conndata = cd[0]
	}

	conn, err := mysql.DialTCP(pc.conndata.Host, pc.conndata.User, pc.conndata.Pass, pc.conndata.Name)

	if err != nil {
		return false
	}
	pc.conn = conn
	pc.connected = true
	pc.time = time.Seconds()
	return true
}
Ejemplo n.º 3
0
//Pull information from MySQL to find out which API keys we should handle and how they map
//  i.e. servers and cores
func loadSolrServers(config map[string]map[string]string) map[string]map[string]string {
	db, err := mysql.DialTCP(config["database"]["host"], config["database"]["user"], config["database"]["pass"], config["database"]["name"])
	if err != nil {
		l4g.Error("Error connecting to db: %s\n", err.String())
		os.Exit(1)
	}
	stmt, err := db.Prepare("Select apistring,core,server,authstring from cores where gosolr = ?")
	if err != nil {
		l4g.Error("Error preparing statement: %s", err.String())
		os.Exit(1)
	}

	stmt.BindParams(config["default"]["host"])

	err = stmt.Execute()
	if err != nil {
		l4g.Error("error executing stmt: %s", err.String())
		os.Exit(1)
	}

	var solrrow SolrData
	stmt.BindResult(&solrrow.apistring, &solrrow.core, &solrrow.server, &solrrow.authstring)
	solr_values := make(map[string]map[string]string)

	for {
		eof, err := stmt.Fetch()
		if err != nil {
			l4g.Error("Error fetching row: %s", err.String())
			os.Exit(1)
		}

		solr_values[solrrow.apistring] = map[string]string{"core": solrrow.core, "server": solrrow.server, "authstring": solrrow.authstring}
		if eof {
			break
		}
	}
	return solr_values
}