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


Golang Context.PutString方法代码示例

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


在下文中一共展示了Context.PutString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Delete

func Delete(ctx context.Context) error {
	appNames, _ := ctx.GetString("appNames")
	if appNames == "" {
		return errors.New("No app to delete")
	}
	appNamesArray := strings.Split(appNames, ",")
	appNameToDelete := appNamesArray[len(appNamesArray)-1]

	appNames = strings.Replace(appNames, ","+appNameToDelete, "", -1)
	appNames = strings.Replace(appNames, appNameToDelete, "", -1)
	ctx.PutString("appNames", appNames)
	return expectCfToSay("Deleting app", "delete", appNameToDelete, "-f")
}
开发者ID:nkuacac,项目名称:pat,代码行数:13,代码来源:cf.go

示例3: Target

func (r *rest) Target(ctx context.Context) error {
	var target string
	if _, ok := ctx.GetString("rest:target"); ok {
		target, _ = ctx.GetString("rest:target")
	} else {
		return errors.New("argument rest:target does not exist")
	}

	body := &TargetResponse{}
	return r.GetSuccessfully("", target+"/v2/info", nil, body, func(reply Reply) error {
		ctx.PutString("loginEndpoint", body.LoginEndpoint)
		ctx.PutString("apiEndpoint", target)
		return nil
	})
}
开发者ID:nkuacac,项目名称:pat,代码行数:15,代码来源:rest.go

示例4: PopulateAppContext

func PopulateAppContext(appPath string, manifestPath string, ctx context.Context) error {
	normalizedAppPath, err := normalizePath(appPath)
	if err != nil {
		return err
	}
	ctx.PutString("app", normalizedAppPath)

	normalizedManifestPath, err := normalizePath(manifestPath)
	if err != nil {
		return err
	}
	ctx.PutString("app:manifest", normalizedManifestPath)

	return nil
}
开发者ID:nkuacac,项目名称:pat,代码行数:15,代码来源:workloads.go

示例5: Dummy

func Dummy(ctx context.Context) error {
	guid, _ := uuid.NewV4()
	appName := "pats-" + guid.String()
	appNames, _ := ctx.GetString("appNames")

	if appNames != "" {
		appNames += fmt.Sprintf(",%s", appName)
	} else {
		appNames = appName
	}
	ctx.PutString("appNames", appNames)

	time.Sleep(time.Duration(random(1, 5)) * time.Second)
	return nil
}
开发者ID:nkuacac,项目名称:pat,代码行数:15,代码来源:cf.go

示例6: targetSpace

func (r *rest) targetSpace(ctx context.Context) error {
	apiEndpoint, _ := ctx.GetString("apiEndpoint")

	var space string
	if _, ok := ctx.GetString("rest:space"); ok {
		space, _ = ctx.GetString("rest:space")
	} else {
		return errors.New("argument rest:space does not exist")
	}
	replyBody := &SpaceResponse{}

	return checkLoggedIn(ctx, func(token string) error {
		return r.GetSuccessfully(token, fmt.Sprintf("%s/v2/spaces?q=name:%s", apiEndpoint, space), nil, replyBody, func(reply Reply) error {
			return checkSpaceExists(replyBody, func() error {
				ctx.PutString("space_guid", replyBody.Resources[0].Metadata.Guid)
				return nil
			})
		})
	})
}
开发者ID:nkuacac,项目名称:pat,代码行数:20,代码来源:rest.go

示例7: Push

func Push(ctx context.Context) error {
	guid, _ := uuid.NewV4()
	pathToApp, _ := ctx.GetString("app")
	pathToManifest, _ := ctx.GetString("app:manifest")
	appName := "pats-" + guid.String()
	appNames, _ := ctx.GetString("appNames")

	if appNames != "" {
		appNames += fmt.Sprintf(",%s", appName)
	} else {
		appNames = appName
	}
	ctx.PutString("appNames", appNames)

	if pathToManifest == "" {
		return expectCfToSay("App started", "push", appName, "-m", "64M", "-p", pathToApp)
	} else {
		return expectCfToSay("App started", "push", appName, "-p", pathToApp, "-f", pathToManifest)
	}
}
开发者ID:nkuacac,项目名称:pat,代码行数:20,代码来源:cf.go

示例8:

	. "github.com/onsi/gomega"
)

var _ = Describe("Context map", func() {

	var (
		localContext context.Context
	)

	JustBeforeEach(func() {
		localContext = context.New()
	})

	Context("String values in context map", func() {
		It("uses a key to identify store fields", func() {
			localContext.PutString("key1", "abc")
			localContext.PutString("key2", "123")

			result, exists := localContext.GetString("key1")
			Ω(result).Should(Equal("abc"))
			Ω(exists).Should(Equal(true))

			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")
开发者ID:nkuacac,项目名称:pat,代码行数:31,代码来源:context_test.go

示例9: PopulateRestContext

func PopulateRestContext(target string, username string, password string, space string, ctx context.Context) {
	ctx.PutString("rest:target", target)
	ctx.PutString("rest:username", username)
	ctx.PutString("rest:password", password)
	ctx.PutString("rest:space", space)
}
开发者ID:nkuacac,项目名称:pat,代码行数:6,代码来源:rest.go

示例10:

					Ω(result.Steps).Should(HaveLen(2))
					Ω(result.Steps[0].Duration.Seconds()).Should(BeNumerically("~", 1, 0.1))
					Ω(result.Steps[1].Duration.Seconds()).Should(BeNumerically("~", 2, 0.1))
				})
			})

			Describe("Workload context map sending over Redis", func() {

				AfterEach(func() {
					workloadCtx = context.New()
				})

				Describe("Contents in the context map", func() {
					It("should send all the keys in the context over redis", func() {
						worker := NewRedisWorker(conn)
						workloadCtx.PutString("cfUsername", "user1")
						workloadCtx.PutString("RandomKey", "some info")
						_ = worker.Time("recordWorkerInfo", workloadCtx)
						Ω(wasCalledWithWorkerUsername).Should(Equal("user1"))
						Ω(wasCalledWithRandomKey).Should(Equal("some info"))
					})

					It("should retain 'int' type content when sending over redis", func() {
						worker := NewRedisWorker(conn)
						workloadCtx.PutInt("iterationIndex", 100)
						_ = worker.Time("recordWorkerIndex", workloadCtx)
						Ω(wasCalledWithWorkerIndex).Should(Equal(100))
					})

					It("should retain 'bool' type content when sending over redis", func() {
						worker := NewRedisWorker(conn)
开发者ID:nkuacac,项目名称:pat,代码行数:31,代码来源:redis_test.go


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