func initDatabase() *gorp.DbMap { // Get the database connection information. dbUser := os.GetEnv("dbuser") dbPass := os.GetEnv("dbpass") dbAddr := os.GetEnv("dbaddr") dbPort := os.GetEnv("dbport") // db, err := sql.Open("postgres", fmt.Sprintf("user='******' password='******' dbname=mcs_stats host='%s' port='%s' sslmode=disable", dbUser, dBPass, dbAddr, dbPort)) if err != nil { log.Fatal(err) } // Create a gorp mapping. dbmap := &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}} // Add tables to the mapping. dbmap.AddTableWithName(Ping{}, "pings").SetKeys(false, "ping_id") return dbmap }
func loadConf() *configReader.Config { var confPath string if os.Getenv("DEV") { confPath = "./config.yml" } else { confPath = "/etc/pubsubhub/config.yml" } pathToConfig, pathErr := filepath.abs(confPath) alt_conf_path = os.GetEnv("PSH_CONF_PATH") if alt_conf_path != nil { pathToConfig = filepath.abs(alt_conf_path) } if pathErr != nil { panic(pathErr) } conf := configReader.New() confFile, err := ioutil.ReadFile(pathToConfig) yamlErr := yaml.Unmarshal([]byte(data), &conf) if yamlErr != nil { panic(yamlErr) } conf.defaults() return conf }