コード例 #1
0
ファイル: main.go プロジェクト: nii236/go-react-webpack
func main() {
	// Create service
	service := goa.New("API")
	logger := log15.New()
	goa.Log = goalog15.New(logger)
	// Setup middleware
	service.Use(middleware.RequestID())
	service.Use(middleware.LogRequest(true))
	service.Use(middleware.Recover())

	cspec, err := cors.New(func() {
		cors.Origin("*", func() {
			cors.Resource("/*", func() {
				cors.Headers("Accept", "Content-Type", "Origin", "Authorization")
				cors.Methods("GET", "POST", "PUT", "DELETE", "OPTIONS")
				cors.MaxAge(600)
				cors.Credentials(true)
				cors.Vary("Http-Origin")
			})
		})
	})
	if err != nil {
		panic(err)
	}
	// mount the cors controller
	service.Use(cors.Middleware(cspec))
	cors.MountPreflightController(service, cspec)

	// Mount "authentication" controller
	c := NewAuthenticationController(service)
	app.MountAuthenticationController(service, c)
	// Mount "operands" controller
	c2 := NewOperandsController(service)
	app.MountOperandsController(service, c2)
	// Mount "ui" controller
	ui.MountController(service)
	// Mount Swagger spec provider controller
	swagger.MountController(service)

	// Start service, listen on port 8080
	service.ListenAndServe(":8080")
	fmt.Println("a ...interface{}")
}
コード例 #2
0
			It("sets the resource credentials flag", func() {
				Ω(spec).Should(HaveLen(1))
				Ω(spec[0]).ShouldNot(BeNil())
				Ω(spec[0].Credentials).Should(Equal(credentials))
			})
		})

		Context("Vary", func() {
			vary := []string{"X-Origin"}

			BeforeEach(func() {
				dsl = func() {
					cors.Origin(origin, func() {
						cors.Resource(path, func() {
							cors.Vary(vary[0])
						})
					})
				}
			})

			It("sets the resource 'Vary' response header", func() {
				Ω(spec).Should(HaveLen(1))
				Ω(spec[0]).ShouldNot(BeNil())
				Ω(spec[0].Vary).Should(HaveLen(len(vary)))
				for i, h := range spec[0].Vary {
					Ω(h).Should(Equal(vary[i]))
				}
			})
		})