本文整理汇总了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)
})
})
}
示例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)))
示例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))