当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.GetInt方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/pat/context.Context.GetInt方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetInt方法的具体用法?Golang Context.GetInt怎么用?Golang Context.GetInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry-incubator/pat/context.Context的用法示例。


在下文中一共展示了Context.GetInt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Login

func (r *rest) Login(ctx context.Context) error {
	body := &LoginResponse{}

	iterationIndex, exist := ctx.GetInt("iterationIndex")
	if !exist {
		return errors.New("Iteration Index does not exist in context map")
	}

	var userList, passList string
	if _, ok := ctx.GetString("rest:username"); ok {
		userList, _ = ctx.GetString("rest:username")
	} else {
		return errors.New("argument rest:username does not exist")
	}
	if _, ok := ctx.GetString("rest:password"); ok {
		passList, _ = ctx.GetString("rest:password")
	} else {
		return errors.New("argument rest:password does not exist")
	}

	return checkTargetted(ctx, func(loginEndpoint string, apiEndpoint string) error {
		return r.PostToUaaSuccessfully(fmt.Sprintf("%s/oauth/token", loginEndpoint), r.oauthInputs(credentialsForWorker(iterationIndex, userList, passList)), body, func(reply Reply) error {
			ctx.PutString("token", body.Token)
			return r.targetSpace(ctx)
		})
	})
}
开发者ID:nkuacac,项目名称:pat,代码行数:27,代码来源:rest.go

示例2:

			result, exists = localContext.GetString("key2")
			Ω(result).Should(Equal("123"))
			Ω(exists).Should(Equal(true))
		})

		It("can store string value as provided", func() {
			localContext.PutString("str", "This is a long string \n")

			result, _ := localContext.GetString("str")
			Ω(result).Should(Equal("This is a long string \n"))
		})

		It("can store int value as provided", func() {
			localContext.PutInt("int", 123)

			result, _ := localContext.GetInt("int")
			Ω(result).Should(Equal(123))
		})

		It("can store bool value as provided", func() {
			localContext.PutBool("key", true)

			result, _ := localContext.GetBool("key")
			Ω(result).Should(Equal(true))
		})

		It("can store float64 value as provided", func() {
			localContext.PutFloat64("key", float64(3.14))

			result, _ := localContext.GetFloat64("key")
			Ω(result).Should(Equal(float64(3.14)))
开发者ID:nkuacac,项目名称:pat,代码行数:31,代码来源:context_test.go

示例3:

				worker := NewRedisWorker(conn)
				result := worker.Time("foo", workloadCtx)
				Ω(result.Steps[0].Command).Should(Equal("foo"))
			})

			It("Returns any errors", func() {
				worker := NewRedisWorker(conn)
				result := worker.Time("stepWithError", workloadCtx)
				Ω(result.Error).Should(HaveOccurred())
			})

			It("Passes workload to each step", func() {
				worker := NewRedisWorker(conn)
				worker.Time("fooWithContext,barWithContext", workloadCtx)

				result, exists := workloadCtx.GetInt("a")
				Ω(exists).Should(Equal(true))
				Ω(result).Should(Equal(3))
			})

			Describe("When multiple steps are provided separated by commas", func() {
				var result IterationResult

				JustBeforeEach(func() {
					worker := NewRedisWorkerWithTimeout(conn, 5)
					result = worker.Time("foo,bar", workloadCtx)
					Ω(result.Error).Should(BeNil())
				})

				It("Reports the total time", func() {
					Ω(result.Duration.Seconds()).Should(BeNumerically("~", 3, 0.1))
开发者ID:nkuacac,项目名称:pat,代码行数:31,代码来源:redis_test.go


注:本文中的github.com/cloudfoundry-incubator/pat/context.Context.GetInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。