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


Golang context.Context类代码示例

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


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

示例1: checkLoggedIn

func checkLoggedIn(ctx context.Context, then func(token string) error) error {
	if _, exists := ctx.GetString("token"); !exists {
		return errors.New("Error: not logged in")
	}

	token, _ := ctx.GetString("token")
	return then(token)
}
开发者ID:nkuacac,项目名称:pat,代码行数:8,代码来源:rest.go

示例2: uploadAppBitsSuccessfully

func (r *rest) uploadAppBitsSuccessfully(ctx context.Context, appUri string, then func() error) error {
	apiEndpoint, _ := ctx.GetString("apiEndpoint")

	return checkLoggedIn(ctx, func(token string) error {
		return withGeneratedAppBits(func(b *bytes.Buffer, m *multipart.Writer) error {
			return r.MultipartPutSuccessfully(token, m, fmt.Sprintf("%s%s/bits", apiEndpoint, appUri), b, nil, func(reply Reply) error {
				return then()
			})
		})
	})
}
开发者ID:nkuacac,项目名称:pat,代码行数:11,代码来源:rest.go

示例3: start

func (r *rest) start(ctx context.Context, appUri string, then func() error) error {
	apiEndpoint, _ := ctx.GetString("apiEndpoint")

	input := make(map[string]interface{})
	input["state"] = "STARTED"
	return checkLoggedIn(ctx, func(token string) error {
		return r.PutSuccessfully(token, fmt.Sprintf("%s%s", apiEndpoint, appUri), input, nil, func(reply Reply) error {
			return then()
		})
	})
}
开发者ID:nkuacac,项目名称:pat,代码行数:11,代码来源:rest.go

示例4: 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

示例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: 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

示例7: createAppSuccessfully

func (r *rest) createAppSuccessfully(ctx context.Context, thenWithLocation func(appUri string) error) error {
	apiEndpoint, _ := ctx.GetString("apiEndpoint")
	space_guid, _ := ctx.GetString("space_guid")

	uuid, _ := uuid.NewV4()
	createApp := struct {
		Name      string `json:"name"`
		SpaceGuid string `json:"space_guid"`
	}{uuid.String(), space_guid}

	return checkLoggedIn(ctx, func(token string) error {
		return r.PostSuccessfully(token, fmt.Sprintf("%s/v2/apps", apiEndpoint), createApp, nil, func(reply Reply) error {
			return thenWithLocation(reply.Location)
		})
	})
}
开发者ID:nkuacac,项目名称:pat,代码行数:16,代码来源:rest.go

示例8: ExecuteConcurrently

func ExecuteConcurrently(schedule <-chan int, tasks <-chan func(context.Context), workloadCtx context.Context) {
	var wg sync.WaitGroup
	indexCounter := 0

	for increment := range schedule {

		for i := 0; i < increment; i++ {
			wg.Add(1)
			go func(t <-chan func(context.Context), ctx context.Context) {
				defer wg.Done()
				for task := range t {
					ctx.PutInt("iterationIndex", indexCounter)
					indexCounter++
					task(ctx)
				}
			}(tasks, workloadCtx.Clone())
		}
	}
	wg.Wait()
}
开发者ID:nkuacac,项目名称:pat,代码行数:20,代码来源:benchmarker.go

示例9: checkTargetted

func checkTargetted(ctx context.Context, then func(loginEndpoint string, apiEndpoint string) error) error {
	if _, exists := ctx.GetString("loginEndpoint"); !exists {
		return errors.New("Not targetted")
	}

	if _, exists := ctx.GetString("apiEndpoint"); !exists {
		return errors.New("Not targetted")
	}

	apiEndpoint, _ := ctx.GetString("apiEndpoint")
	loginEndpoint, _ := ctx.GetString("loginEndpoint")
	return then(loginEndpoint, apiEndpoint)
}
开发者ID:nkuacac,项目名称:pat,代码行数:13,代码来源:rest.go

示例10: trackAppStart

func (r *rest) trackAppStart(ctx context.Context, appUri string) error {
	return checkLoggedIn(ctx, func(token string) error {
		apiEndpoint, _ := ctx.GetString("apiEndpoint")
		for {
			decoded := make(map[string]interface{})
			reply := r.client.Get(token, fmt.Sprintf("%s%s/instances", apiEndpoint, appUri), nil, &decoded)

			if reply.Code < 400 || decoded["error_code"] != "CF-NotStaged" {
				if decoded["error_code"] != nil {
					return errors.New("App Failed to Stage")
				}
				break
			}

			time.Sleep(2 * time.Second)
		}

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

示例11: GenerateAndPush

func GenerateAndPush(ctx context.Context) error {
	pathToApp, _ := ctx.GetString("app")
	pathToManifest, _ := ctx.GetString("app:manifest")

	guid, _ := uuid.NewV4()
	rand.Seed(time.Now().UTC().UnixNano())
	salt := strconv.FormatInt(rand.Int63(), 10)

	dstDir := path.Join(os.TempDir(), salt)
	defer os.RemoveAll(dstDir)

	err := CopyAndReplaceText(pathToApp, dstDir, "$RANDOM_TEXT", salt)
	if err != nil {
		return err
	}

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

示例12: 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

示例13: 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

示例14: 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

示例15:

package context_test

import (
	"github.com/cloudfoundry-incubator/pat/context"
	. "github.com/onsi/ginkgo"
	. "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))
		})
开发者ID:nkuacac,项目名称:pat,代码行数:31,代码来源:context_test.go


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