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") }
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") }
func init() { // Configure logging for appengine goa.Log.SetHandler(log15.MultiHandler( log15.StreamHandler(os.Stderr, log15.LogfmtFormat()), AppEngineLogHandler()), ) // Create goa application service := goa.New("cellar") // Setup CORS to allow for swagger UI. spec, err := cors.New(func() { cors.Origin("*", func() { cors.Resource("*", func() { cors.Methods("GET", "POST", "PUT", "PATCH", "DELETE") cors.Headers("*") }) }) }) if err != nil { panic(err) } // Setup basic middleware service.Use(goa.RequestID()) service.Use(AppEngineLogCtx()) service.Use(cors.Middleware(spec)) service.Use(goa.Recover()) // Mount account controller onto application ac := controllers.NewAccount(service) app.MountAccountController(service, ac) // Mount bottle controller onto application bc := controllers.NewBottle(service) app.MountBottleController(service, bc) // Mount Swagger Spec controller onto application swagger.MountController(service) // Mount CORS preflight controllers cors.MountPreflightController(service, spec) // Setup HTTP handler http.HandleFunc("/", service.HTTPHandler().ServeHTTP) }
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") }
const reqID = "request id" var ctx *goa.Context BeforeEach(func() { req, err := http.NewRequest("GET", "/goo", nil) Ω(err).ShouldNot(HaveOccurred()) req.Header.Set("X-Request-Id", reqID) ctx = goa.NewContext(nil, req, new(TestResponseWriter), nil, nil) }) It("sets the request ID in the context", func() { h := func(ctx *goa.Context) error { ctx.JSON(200, "ok") return nil } rg := goa.RequestID()(h) Ω(rg(ctx)).ShouldNot(HaveOccurred()) Ω(ctx.Value(goa.ReqIDKey)).Should(Equal(reqID)) }) }) var _ = Describe("Recover", func() { It("recovers", func() { h := func(ctx *goa.Context) error { panic("boom") } rg := goa.Recover()(h) err := rg(goa.NewContext(nil, nil, nil, nil, nil)) Ω(err).Should(HaveOccurred()) Ω(err.Error()).Should(Equal("panic: boom")) })
It("initializes the application fields", func() { Ω(s.Name()).Should(Equal(appName)) Ω(s).Should(BeAssignableToTypeOf(&goa.Application{})) app, _ := s.(*goa.Application) Ω(app.Name()).Should(Equal(appName)) Ω(app.Logger).ShouldNot(BeNil()) Ω(app.Router).ShouldNot(BeNil()) }) }) Describe("Use", func() { Context("with a valid middleware", func() { var m goa.Middleware BeforeEach(func() { m = goa.RequestID() }) JustBeforeEach(func() { s.Use(m) }) It("adds the middleware", func() { ctrl := s.NewController("test") Ω(ctrl.MiddlewareChain()).Should(HaveLen(1)) Ω(ctrl.MiddlewareChain()[0]).Should(BeAssignableToTypeOf(goa.RequestID())) }) }) }) Describe("NewHTTPRouterHandle", func() {