Exemplo n.º 1
0
func Setup() *settings.AppContext {
	connect_str := fmt.Sprintf("user=tinyplannr dbname=tinyplannr_test password=%s sslmode=disable", os.Getenv("TP_PW"))
	db, _ := sqlx.Connect("postgres", connect_str)

	cookie_key, _ := base64.StdEncoding.DecodeString(os.Getenv("TINYPLANNR_SC_HASH"))
	cookie_block, _ := base64.StdEncoding.DecodeString(os.Getenv("TINYPLANNR_SC_BLOCK"))

	context := &settings.AppContext{
		Db:            db,
		CookieMachine: securecookie.New(cookie_key, cookie_block),
	}

	server = httptest.NewServer(router.ApiRouter(context))
	fmt.Println("Test server running...")

	return context
}
Exemplo n.º 2
0
func Api() *mux.Router {
	connect_str := fmt.Sprintf("user=tinyplannr dbname=tinyplannr password=%s sslmode=disable", os.Getenv("TP_PW"))
	db, _ := sqlx.Connect("postgres", connect_str)
	tx := db.MustBegin()

	cookie_key, _ := base64.StdEncoding.DecodeString(os.Getenv("TINYPLANNR_SC_HASH"))
	cookie_block, _ := base64.StdEncoding.DecodeString(os.Getenv("TINYPLANNR_SC_BLOCK"))

	context := &settings.AppContext{
		Db:            db,
		Tx:            tx,
		CookieMachine: securecookie.New(cookie_key, cookie_block),
	}

	router := router.ApiRouter(context)

	return router
}