Пример #1
0
// MountPreflightController mounts the handlers for the CORS preflight requests onto service.
func MountPreflightController(service goa.Service, spec Specification) {
	router := service.HTTPHandler().(*httprouter.Router)
	for _, res := range spec {
		path := res.Path
		if res.IsPathPrefix {
			if strings.HasSuffix(path, "/") {
				path += "*cors"
			} else {
				path += "/*cors"
			}
		}
		var handle httprouter.Handle
		handle, _, tsr := router.Lookup("OPTIONS", path)
		if tsr {
			if strings.HasSuffix(path, "/") {
				path = path[:len(path)-1]
			} else {
				path = path + "/"
			}
			handle, _, _ = router.Lookup("OPTIONS", path)
		}
		if handle == nil {
			h := func(ctx *goa.Context) error {
				return ctx.Respond(200, nil)
			}
			ctrl := service.NewController("cors")
			router.OPTIONS(path, ctrl.NewHTTPRouterHandle("preflight", h))
		}
	}
}
Пример #2
0
// MountPreflightController mounts the handlers for the CORS preflight requests onto service.
func MountPreflightController(service goa.Service, spec Specification) {
	for _, res := range spec {
		path := res.Path
		if res.IsPathPrefix {
			if strings.HasSuffix(path, "/") {
				path += "*cors"
			} else {
				path += "/*cors"
			}
		}
		handle := service.ServeMux().Lookup("OPTIONS", path)
		if handle == nil {
			h := func(ctx *goa.Context) error {
				return ctx.Respond(200, nil)
			}
			ctrl := service.NewController("cors")
			service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("preflight", h))
		}
	}
}
Пример #3
0
// NewAccountController creates a account controller.
func NewAccountController(service goa.Service) AccountController {
	return &AccountController{Controller: service.NewController("AccountController")}
}
Пример #4
0
// NewBottleController creates a bottle controller.
func NewBottleController(service goa.Service) BottleController {
	return &BottleController{Controller: service.NewController("BottleController")}
}
Пример #5
0
						return err
					}
					c.SetPayload(payload)
				}
				return nil
			}
			var err error
			reader := strings.NewReader(reqBody)
			request, err = http.NewRequest("POST", "/foo?filters=one&filters=two&filters=three", reader)
			Ω(err).ShouldNot(HaveOccurred())
			rw = new(TestResponseWriter)
			params = url.Values{"id": []string{"42"}, "filters": []string{"one", "two", "three"}}
		})

		JustBeforeEach(func() {
			ctrl := app.NewController(resName)
			handleFunc = ctrl.HandleFunc(actName, handler, unmarshaler)
			handleFunc(rw, request, params)
		})

		Describe("Respond", func() {
			It("sets the context fields", func() {
				Ω(ctx.Request()).Should(Equal(request))
				Ω(ctx.Header()).Should(Equal(rw.Header()))
				Ω(ctx.ResponseStatus()).Should(Equal(respStatus))
				Ω(ctx.ResponseLength()).Should(Equal(len(respContent)))
				p := ctx.Get("id")
				Ω(p).Should(Equal("42"))
				ps := ctx.GetMany("filters")
				Ω(ps).Should(Equal([]string{"one", "two", "three"}))
				var payload string
Пример #6
0
	})

	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() {
		const resName = "res"
		const actName = "act"
		var handler goa.Handler
		const respStatus = 200
		var respContent = []byte("response")

		var httpHandle httprouter.Handle
		var ctx *goa.Context
Пример #7
0
// NewBottle creates a bottle controller.
func NewBottle(service goa.Service) *BottleController {
	return &BottleController{
		Controller: service.NewController("Bottle"),
		db:         NewDB(),
	}
}
Пример #8
0
// MountController mounts the swagger spec controller under "/swagger.json".
func MountController(service goa.Service) {
	ctrl := service.NewController("Swagger")
	service.Info("mount", "ctrl", "Swagger", "action", "Show", "route", "GET /swagger.json")
	h := ctrl.NewHTTPRouterHandle("Show", getSwagger)
	service.HTTPHandler().(*httprouter.Router).Handle("GET", "/swagger.json", h)
}
Пример #9
0
// NewAccount creates a account controller.
func NewAccount(service goa.Service) *AccountController {
	return &AccountController{
		Controller: service.NewController("Account"),
		db:         NewDB(),
	}
}