• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang context.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


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


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


示例18:

	"io"
	"os/exec"
	"path/filepath"
	"runtime"
	"time"

	"github.com/cloudfoundry-incubator/pat/context"
	"github.com/cloudfoundry-incubator/pat/redis"
	"github.com/cloudfoundry-incubator/pat/workloads"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RedisWorker", func() {
	var (
		conn        redis.Conn
		workloadCtx context.Context
	)

	BeforeEach(func() {
		StartRedis("../redis/redis.conf")
		var err error
		conn, err = redis.Connect("", 63798, "p4ssw0rd")
		Ω(err).ShouldNot(HaveOccurred())
		workloadCtx = context.New()
	})

	AfterEach(func() {
		StopRedis()
	})

	Describe("When a single experiment is provided", func() {
开发者ID:nkuacac,项目名称:pat,代码行数:32,代码来源:redis_test.go


示例19:

			return
		}
	})

	JustBeforeEach(func() {
		flags = config.NewConfig()
		InitCommandLineFlags(flags)
		flags.Parse(args)

		BlockExit = func() {}
		err = RunCommandLine()
	})

	Describe("When rest parmaters are supplied", func() {
		var (
			ctx context.Context
		)

		BeforeEach(func() {
			ctx = context.New()
			args = []string{"-rest:target", "someTarget",
				"-rest:username", "someUser",
				"-rest:password", "hunter2",
				"-rest:space", "theFinalFrontier",
			}
			NewContext = func() context.Context {
				return ctx
			}
		})

		It("configures the experiment with the parameter", func() {
开发者ID:nkuacac,项目名称:pat,代码行数:31,代码来源:cmdline_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang receptor.Client类代码示例发布时间:2022-05-23
下一篇:
Golang config.Config类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap