當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.ResponseStatus方法代碼示例

本文整理匯總了Golang中github.com/raphael/goa.Context.ResponseStatus方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.ResponseStatus方法的具體用法?Golang Context.ResponseStatus怎麽用?Golang Context.ResponseStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/raphael/goa.Context的用法示例。


在下文中一共展示了Context.ResponseStatus方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

		It("returns the middleware", func() {
			Ω(fmt.Sprintf("%#v", middleware)).Should(Equal(fmt.Sprintf("%#v", goa.Middleware(goaMiddlewareFunc))))
			Ω(mErr).ShouldNot(HaveOccurred())
		})
	})

	Context("with a context", func() {
		var ctx *goa.Context

		BeforeEach(func() {
			req, err := http.NewRequest("GET", "/goo", nil)
			Ω(err).ShouldNot(HaveOccurred())
			rw := new(TestResponseWriter)
			params := url.Values{"foo": []string{"bar"}}
			ctx = goa.NewContext(nil, req, rw, params, nil)
			Ω(ctx.ResponseStatus()).Should(Equal(0))
		})

		Context("using a goa handler", func() {
			BeforeEach(func() {
				var goaHandler goa.Handler = func(ctx *goa.Context) error {
					ctx.JSON(200, "ok")
					return nil
				}
				input = goaHandler
			})

			It("wraps it in a middleware", func() {
				Ω(mErr).ShouldNot(HaveOccurred())
				h := func(ctx *goa.Context) error { return nil }
				Ω(middleware(h)(ctx)).ShouldNot(HaveOccurred())
開發者ID:tashanji,項目名稱:goa,代碼行數:31,代碼來源:middleware_test.go

示例2:

	Describe("Request", func() {
		It("returns nil if not initialized", func() {
			Ω(ctx.Request()).Should(BeNil())
		})
	})

	Describe("Header", func() {
		It("returns nil if not initialized", func() {
			Ω(ctx.Header()).Should(BeNil())
		})
	})

	Describe("ResponseStatus", func() {
		It("returns 0 if not initialized", func() {
			Ω(ctx.ResponseStatus()).Should(Equal(0))
		})
	})

	Describe("ResponseLength", func() {
		It("returns 0 if not initialized", func() {
			Ω(ctx.ResponseLength()).Should(Equal(0))
		})
	})

	Describe("Get", func() {
		It(`returns "", false if not initialized`, func() {
			p := ctx.Get("foo")
			Ω(p).Should(Equal(""))
		})
	})
開發者ID:yonglehou,項目名稱:goa,代碼行數:30,代碼來源:context_test.go

示例3:

		token = jwtg.New(jwtg.SigningMethodHS256)
		token.Claims["exp"] = time.Now().Add(time.Hour * 24).Unix()
		token.Claims["random"] = "42"
		tokenString, err = token.SignedString(signingKey)
		Ω(err).ShouldNot(HaveOccurred())
	})

	It("requires a jwt token be present", func() {

		h := func(ctx *goa.Context) error {
			ctx.Respond(200, "ok")
			return nil
		}
		jw := jwt.Middleware(spec)(h)
		Ω(jw(ctx)).ShouldNot(HaveOccurred())
		Ω(ctx.ResponseStatus()).Should(Equal(http.StatusUnauthorized))

	})

	It("returns the jwt token that was sent as a header", func() {

		req.Header.Set("Authorization", "bearer "+tokenString)
		h := func(ctx *goa.Context) error {
			ctx.Respond(200, "ok")
			return nil
		}
		jw := jwt.Middleware(spec)(h)
		Ω(jw(ctx)).ShouldNot(HaveOccurred())
		Ω(ctx.ResponseStatus()).Should(Equal(http.StatusOK))
		tok, err := jwtg.Parse(tokenString, validFunc)
		Ω(err).ShouldNot(HaveOccurred())
開發者ID:derekperkins,項目名稱:goa-middleware,代碼行數:31,代碼來源:jwt_test.go

示例4:

		handler = new(testHandler)
		logger := log15.New("test", "test")
		logger.SetHandler(handler)
		ctx.Logger = logger
	})

	It("encodes response using gzip", func() {
		h := func(ctx *goa.Context) error {
			ctx.Write([]byte("gzip me!"))
			ctx.WriteHeader(http.StatusOK)
			return nil
		}
		t := gzm.Middleware(gzip.BestCompression)(h)
		err := t(ctx)
		Ω(err).ShouldNot(HaveOccurred())
		Ω(ctx.ResponseStatus()).Should(Equal(http.StatusOK))

		gzr, err := gzip.NewReader(bytes.NewReader(rw.Body))
		Ω(err).ShouldNot(HaveOccurred())
		buf := bytes.NewBuffer(nil)
		io.Copy(buf, gzr)
		Ω(err).ShouldNot(HaveOccurred())
		Ω(buf.String()).Should(Equal("gzip me!"))
	})

})

type testHandler struct {
	Records []*log15.Record
}
開發者ID:derekperkins,項目名稱:goa-middleware,代碼行數:30,代碼來源:middleware_test.go

示例5:

			provisioningContext.InstanceId = "some-instance-id"
			provisioningContext.OrganizationId = "org-1"
			provisioningContext.SpaceId = "space-1"
			provisioningContext.ServiceId = "service-1"
			provisioningContext.PlanId = "plan-1"
		})

		Context("when all goes ok", func() {
			BeforeEach(func() {
				err := provisioningController.Create(provisioningContext)
				Expect(err).ToNot(HaveOccurred())
			})

			It("responds with 201", func() {
				Expect(goaContext.ResponseStatus()).To(Equal(201))
			})

			It("sends the correct message to the state", func() {
				recordedInstance := state.AddInstanceArgsForCall(0)
				Expect(recordedInstance.ID).To(Equal("some-instance-id"))
				Expect(recordedInstance.OrganizationID).To(Equal("org-1"))
				Expect(recordedInstance.SpaceID).To(Equal("space-1"))
				Expect(recordedInstance.ServiceID).To(Equal("service-1"))
				Expect(recordedInstance.PlanID).To(Equal("plan-1"))
			})
		})

		Context("when the instance id already exists", func() {
			BeforeEach(func() {
				state.InstanceExistsReturns(true)
開發者ID:tscolari,項目名稱:memcached-broker,代碼行數:30,代碼來源:provisioning_test.go

示例6:

			Ω(mErr).ShouldNot(HaveOccurred())
		})
	})

	Context("with a context", func() {
		var service goa.Service
		var ctx *goa.Context

		BeforeEach(func() {
			service = goa.New("test")
			req, err := http.NewRequest("GET", "/goo", nil)
			Ω(err).ShouldNot(HaveOccurred())
			rw := new(TestResponseWriter)
			params := url.Values{"foo": []string{"bar"}}
			ctx = goa.NewContext(nil, service, req, rw, params)
			Ω(ctx.ResponseStatus()).Should(Equal(0))
		})

		Context("using a goa handler", func() {
			BeforeEach(func() {
				var goaHandler goa.Handler = func(ctx *goa.Context) error {
					ctx.Respond(200, "ok")
					return nil
				}
				input = goaHandler
			})

			It("wraps it in a middleware", func() {
				Ω(mErr).ShouldNot(HaveOccurred())
				h := func(ctx *goa.Context) error { return nil }
				Ω(middleware(h)(ctx)).ShouldNot(HaveOccurred())
開發者ID:minloved,項目名稱:goa,代碼行數:31,代碼來源:middleware_test.go


注:本文中的github.com/raphael/goa.Context.ResponseStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。