Example #1
0
func setupServerUser(db *sqlx.DB, tokenSecret []byte) (*httptest.Server, error) {
	r := router.New()

	r.Default(
		handlers.SetConfig(db, []byte(tokenSecret)),
	)

	r.POST("/signup", handlers.Signup)
	r.POST("/oauth/token", handlers.UserToken)

	return httptest.NewServer(r), nil
}
Example #2
0
func setupServerHub(db *sqlx.DB, tokenSecret []byte) (*httptest.Server, error) {
	r := router.New()

	r.Default(
		handlers.SetConfig(db, []byte(tokenSecret)),
	)

	r.GET("/api/v0/hub", handlers.Auth, handlers.AddHub)
	r.POST("/api/v0/hub", handlers.Auth, handlers.ShowHub)
	r.DELETE("/api/v0/hub", handlers.Auth, handlers.DeleteHub)

	return httptest.NewServer(r), nil
}
Example #3
0
func setupServer(db *sqlx.DB, tokenSecret []byte) (*httptest.Server, error) {
	r := router.New()

	r.Default(
		handlers.SetConfig(db, []byte(tokenSecret)),
		handlers.Auth,
	)

	r.GET("/api/v0/*endpoint", func(w http.ResponseWriter, r *http.Request, c router.Context) error {
		w.Header().Set("Content-Type", "application/json;charset=UTF-8")
		w.Write([]byte(`{"status":"ok"}`))
		return nil
	})

	return httptest.NewServer(r), nil
}
Example #4
0
File: cloud.go Project: jhbsz/cloud
func main() {
	db, err := sqlx.Open("postgres", dbURL)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	r := router.New()

	// default handlers are applied to all routes
	r.Default(handlers.SetConfig(db, []byte(tokenSecret)))

	// unauthenticated routes
	r.POST("/signup", handlers.Signup)
	r.POST("/oauth/token", handlers.UserToken)

	// authenticated routes
	r.POST("/api/v0/hub", handlers.Auth, handlers.AddHub)
	r.GET("/api/v0/hub", handlers.Auth, handlers.ShowHub)
	r.DELETE("/api/v0/hub", handlers.Auth, handlers.DeleteHub)

	log.Print("[info] Starting server on ", addr)
	log.Fatal(http.ListenAndServe(addr, r))
}