Пример #1
0
Файл: main.go Проект: tylerb/goa
func main() {
	// Create goa service
	service := goa.New("cellar")

	// Setup basic middleware
	service.Use(goa.RequestID())
	service.Use(goa.LogRequest())
	service.Use(goa.Recover())

	// Mount account controller onto service
	ac := controllers.NewAccount(service)
	app.MountAccountController(service, ac)

	// Mount bottle controller onto service
	bc := controllers.NewBottle(service)
	app.MountBottleController(service, bc)

	// Mount Swagger Spec controller onto service
	swagger.MountController(service)

	// Mount JSON Schema controller onto service
	schema.MountController(service)

	// Mount JavaScript example
	js.MountController(service)

	// Run service
	service.ListenAndServe(":8080")
}
Пример #2
0
func main() {
	// Create service
	api := goa.New("API")

	// Setup middleware
	api.Use(goa.RequestID())
	api.Use(goa.LogRequest())
	api.Use(goa.Recover())

	// Mount "account" controller
	c := NewAccountController()
	app.MountAccountController(api, c)
	// Mount "series" controller
	c2 := NewSeriesController()
	app.MountSeriesController(api, c2)
	// Mount "user" controller
	c3 := NewUserController()
	app.MountUserController(api, c3)

	// Mount Swagger spec provider controller
	swagger.MountController(api)

	// Mount json schema controller
	schema.MountController(api)
	// Start service, listen on port 8080
	api.ListenAndServe(":8080")
}
Пример #3
0
func main() {
	// Create service
	api := goa.New("API")

	// Setup middleware
	api.Use(goa.RequestID())
	api.Use(goa.LogRequest())
	api.Use(goa.Recover())

	// Mount "account" controller
	c := NewAccountController()
	app.MountAccountController(api, c)
	// Mount "bottle" controller
	c2 := NewBottleController()
	app.MountBottleController(api, c2)

	// Mount Swagger spec provider controller
	swagger.MountController(api)

	// Start service, listen on port 8080
	api.ListenAndServe(":8080")
}
Пример #4
0
		req, err := http.NewRequest("POST", "/goo", strings.NewReader(`{"payload":42}`))
		Ω(err).ShouldNot(HaveOccurred())
		rw := new(TestResponseWriter)
		ctx = goa.NewContext(nil, req, rw, params, payload)
		handler = new(testHandler)
		logger := log15.New("test", "test")
		logger.SetHandler(handler)
		ctx.Logger = logger
	})

	It("logs requests", func() {
		h := func(ctx *goa.Context) error {
			ctx.JSON(200, "ok")
			return nil
		}
		lg := goa.LogRequest()(h)
		Ω(lg(ctx)).ShouldNot(HaveOccurred())
		Ω(handler.Records).Should(HaveLen(4))

		Ω(handler.Records[0].Ctx).Should(HaveLen(6))
		Ω(handler.Records[0].Ctx[4]).Should(Equal("POST"))
		Ω(handler.Records[0].Ctx[5]).Should(Equal("/goo"))

		Ω(handler.Records[1].Ctx).Should(HaveLen(6))
		Ω(handler.Records[1].Ctx[4]).Should(Equal("param"))
		Ω(handler.Records[1].Ctx[5]).Should(Equal([]string{"value"}))

		Ω(handler.Records[2].Ctx).Should(HaveLen(6))
		Ω(handler.Records[2].Ctx[4]).Should(Equal("payload"))
		Ω(handler.Records[2].Ctx[5]).Should(Equal(42))