Exemplo n.º 1
0
func init() {
	f, err := os.Open(os.Getenv("GOPATH") + "/config/database.json")
	errors.CheckFatalErr(err)

	decoder := json.NewDecoder(f)
	dbConfig := db.DBConfig{}
	err = decoder.Decode(&dbConfig)
	errors.CheckFatalErr(err)

	f, err = os.Open(os.Getenv("GOPATH") + "/config/store.json")
	errors.CheckFatalErr(err)

	decoder = json.NewDecoder(f)
	storeConfig := StoreConfig{}
	err = decoder.Decode(&storeConfig)
	errors.CheckFatalErr(err)

	SessionName = storeConfig.Name

	Store, err = mysqlstore.NewMySQLStore(
		fmt.Sprint(
			dbConfig.User, ":",
			dbConfig.Password, "@/",
			dbConfig.Database,
			"?parseTime=true"),
		"session", "/", 3600, []byte(storeConfig.Key))
	errors.CheckFatalErr(err)

	fmt.Println("Session store created.")
}
Exemplo n.º 2
0
func init() {
	if DB == nil {
		var err error

		f, err := os.Open(os.Getenv("GOPATH") + "/config/database.json")
		errors.CheckFatalErr(err)

		decoder := json.NewDecoder(f)
		config := DBConfig{}
		err = decoder.Decode(&config)
		errors.CheckFatalErr(err)

		DB, err = sqlx.Connect("mysql", fmt.Sprint(
			config.User, ":",
			config.Password, "@/",
			config.Database,
			"?parseTime=true")) // needed to scan time.Time
		errors.CheckFatalErr(err)

		fmt.Printf("Connected to %v database\n", config.Database)
	}
}