Beispiel #1
0
func main() {

	// Load config file
	config := Config{}
	var data, err = ioutil.ReadFile("config.yml")
	err = yaml.Unmarshal([]byte(data), &config)
	if err != nil {
		log.Fatalf("error: %v", err)
	}

	// Establish connection to DB
	var session *r.Session
	session, err = r.Connect(r.ConnectOpts{
		Address: config.DatabaseURI,
	})
	if err != nil {
		log.Fatalln(err.Error())
	}

	bootstrapDB(session, config)

	defer session.Close()

	log.Println("Connected")

	// Instantiate DAOs
	userDAO := UserDAO{DAO{Session: session}}
	postDAO := PostDAO{DAO{Session: session}}
	sessionDAO := SessionDAO{DAO{Session: session}}

	// Instantiate Controllers
	apiController := APIController{
		Controller{Session: session},
		userDAO,
		postDAO,
		sessionDAO,
	}

	goji.Get("/", apiController.Index)
	goji.Post("/post", apiController.CreatePost)
	goji.Get("/post/:id", apiController.GetPost)

	goji.Serve()

}
Beispiel #2
0
//killSession disconnects from the database
func killSession(session *r.Session) {
	session.Close()
}
func TestTravelPlanning(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "TravelPlanning Suite")
}

var _ = BeforeSuite(func() {
	testConn = NewDBSession(database)
})

var _ = AfterSuite(func() {
	_, err := r.DBDrop(database).RunWrite(testConn)
	if err != nil {
		log.Print(err)
	}
	testConn.Close()
})

type resultToken struct {
	TokenString string `json:"token"`
}

func Login() string {
	APIRequest("/login", "POST", loginCredentials, "")

	token := resultToken{}
	json.Unmarshal(Response.Body.Bytes(), &token)

	return token.TokenString
}