コード例 #1
0
ファイル: routes.go プロジェクト: yetis-br/travelPlanning
// NewRouter return the configured routes for this API
func NewRouter(jwtmiddleware *jwt.JWTMiddleware, session *r.Session) rest.App {

	trips := models.Trips{
		Conn: session,
	}

	router, err := rest.MakeRouter(
		rest.Post("/login", jwtmiddleware.LoginHandler),
		rest.Get("/refresh_token", jwtmiddleware.RefreshHandler),
		rest.Get("/trips", trips.GetAllTrips),
		rest.Get("/trips/:id", trips.GetTrip),
		rest.Post("/trips", trips.PostTrip),
		rest.Patch("/trips/:id/updatePlaces", trips.UpdateTripPlaces),
		rest.Delete("/trips/:id/deletePlace/:place", trips.DeleteTripPlaces),
	)
	if err != nil {
		log.Fatal(err)
	}

	return router
}
コード例 #2
0
ファイル: restapi.go プロジェクト: johnnoone/hooky
// New creates a new instance of the Rest API.
func New(s *store.Store, adminPassword string) (*rest.Api, error) {
	db := s.DB()
	models.NewBase(db).EnsureIndex()
	db.Session.Close()

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	api.Use(&BaseMiddleware{
		Store: s,
	})
	api.Use(&rest.JsonpMiddleware{
		CallbackNameKey: "cb",
	})
	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, request *rest.Request) bool {
			return true
		},
		AllowedMethods:                []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowedHeaders:                []string{"Accept", "Content-Type", "Origin", "Authorization"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})
	authBasic := &AuthBasicMiddleware{
		Realm:         "Hooky",
		Authenticator: authenticate(adminPassword),
		Authorizator:  authorize(adminPassword),
	}
	api.Use(&rest.IfMiddleware{
		Condition: func(r *rest.Request) bool {
			return r.URL.Path != "/status"
		},
		IfTrue: authBasic,
	})
	router, err := rest.MakeRouter(
		rest.Get("/authenticate", Authenticate),
		rest.Post("/accounts", PostAccount),
		rest.Get("/accounts", GetAccounts),
		rest.Get("/accounts/:account", GetAccount),
		rest.Patch("/accounts/:account", PatchAccount),
		rest.Delete("/accounts/:account", DeleteAccount),
		rest.Delete("/accounts/:account/applications", DeleteApplications),
		rest.Get("/accounts/:account/applications", GetApplications),
		rest.Get("/accounts/:account/applications/:application", GetApplication),
		rest.Put("/accounts/:account/applications/:application", PutApplication),
		rest.Delete("/accounts/:account/applications/:application", DeleteApplication),
		rest.Get("/accounts/:account/applications/:application/queues", GetQueues),
		rest.Put("/accounts/:account/applications/:application/queues/:queue", PutQueue),
		rest.Delete("/accounts/:account/applications/:application/queues/:queue", DeleteQueue),
		rest.Get("/accounts/:account/applications/:application/queues/:queue", GetQueue),
		rest.Delete("/accounts/:account/applications/:application/queues", DeleteQueues),
		rest.Post("/accounts/:account/applications/:application/tasks", PutTask),
		rest.Get("/accounts/:account/applications/:application/tasks", GetTasks),
		rest.Delete("/accounts/:account/applications/:application/tasks", DeleteTasks),
		rest.Put("/accounts/:account/applications/:application/tasks/:task", PutTask),
		rest.Get("/accounts/:account/applications/:application/tasks/:task", GetTask),
		rest.Delete("/accounts/:account/applications/:application/tasks/:task", DeleteTask),
		rest.Post("/accounts/:account/applications/:application/tasks/:task/attempts", PostAttempt),
		rest.Get("/accounts/:account/applications/:application/tasks/:task/attempts", GetAttempts),
		rest.Get("/status", GetStatus),
	)
	if err != nil {
		return nil, err
	}
	api.SetApp(router)

	return api, nil
}
コード例 #3
0
ファイル: restapi.go プロジェクト: yonglehou/hooky
// New creates a new instance of the Rest API.
func New(s *store.Store, adminPassword string, logStyle string) (*rest.Api, error) {
	api := rest.NewApi()
	if logStyle == "json" {
		api.Use(&rest.AccessLogJsonMiddleware{})
	} else if strings.HasPrefix(logStyle, "apache-") {
		mw := &rest.AccessLogApacheMiddleware{}
		mw.Format = rest.DefaultLogFormat
		if logStyle == "apache-common" {
			mw.Format = rest.CommonLogFormat
		} else if logStyle == "apache-combined" {
			mw.Format = rest.CombinedLogFormat
		}
		api.Use(mw)
	}
	api.Use(rest.DefaultCommonStack...)
	api.Use(&BaseMiddleware{
		Store: s,
	})
	api.Use(&rest.JsonpMiddleware{
		CallbackNameKey: "cb",
	})
	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, request *rest.Request) bool {
			return true
		},
		AllowedMethods:                []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
		AllowedHeaders:                []string{"Accept", "Content-Type", "Origin", "Authorization"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})
	authBasic := &AuthBasicMiddleware{
		Realm:         "Hooky",
		Authenticator: authenticate(adminPassword),
		Authorizator:  authorize(adminPassword),
	}
	api.Use(&rest.IfMiddleware{
		Condition: func(r *rest.Request) bool {
			return r.URL.Path != "/status"
		},
		IfTrue: authBasic,
	})
	router, err := rest.MakeRouter(
		rest.Get("/authenticate", Authenticate),
		rest.Post("/accounts", PostAccount),
		rest.Get("/accounts", GetAccounts),
		rest.Get("/accounts/:account", GetAccount),
		rest.Patch("/accounts/:account", PatchAccount),
		rest.Delete("/accounts/:account", DeleteAccount),
		rest.Delete("/accounts/:account/applications", DeleteApplications),
		rest.Get("/accounts/:account/applications", GetApplications),
		rest.Get("/accounts/:account/applications/:application", GetApplication),
		rest.Put("/accounts/:account/applications/:application", PutApplication),
		rest.Delete("/accounts/:account/applications/:application", DeleteApplication),
		rest.Get("/accounts/:account/applications/:application/queues", GetQueues),
		rest.Put("/accounts/:account/applications/:application/queues/:queue", PutQueue),
		rest.Delete("/accounts/:account/applications/:application/queues/:queue", DeleteQueue),
		rest.Get("/accounts/:account/applications/:application/queues/:queue", GetQueue),
		rest.Delete("/accounts/:account/applications/:application/queues", DeleteQueues),
		rest.Post("/accounts/:account/applications/:application/tasks", PutTask),
		rest.Get("/accounts/:account/applications/:application/tasks", GetTasks),
		rest.Delete("/accounts/:account/applications/:application/tasks", DeleteTasks),
		rest.Put("/accounts/:account/applications/:application/tasks/:task", PutTask),
		rest.Get("/accounts/:account/applications/:application/tasks/:task", GetTask),
		rest.Delete("/accounts/:account/applications/:application/tasks/:task", DeleteTask),
		rest.Post("/accounts/:account/applications/:application/tasks/:task/attempts", PostAttempt),
		rest.Get("/accounts/:account/applications/:application/tasks/:task/attempts", GetAttempts),
		rest.Get("/accounts/:account/applications/:application/tasks/:task/attempts/:attempt", GetAttempt),
		rest.Get("/status", GetStatus),
	)
	if err != nil {
		return nil, err
	}
	api.SetApp(router)

	return api, nil
}