當前位置: 首頁>>代碼示例>>Golang>>正文


Golang stringutils.GenerateRandomAlphaOnlyString函數代碼示例

本文整理匯總了Golang中github.com/docker/docker/pkg/stringutils.GenerateRandomAlphaOnlyString函數的典型用法代碼示例。如果您正苦於以下問題:Golang GenerateRandomAlphaOnlyString函數的具體用法?Golang GenerateRandomAlphaOnlyString怎麽用?Golang GenerateRandomAlphaOnlyString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GenerateRandomAlphaOnlyString函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: newRemoteFileServer

func newRemoteFileServer(ctx *FakeContext) (*remoteFileServer, error) {
	var (
		image     = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
		container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
	)

	// Build the image
	if err := fakeContextAddDockerfile(ctx, `FROM httpserver
COPY . /static`); err != nil {
		return nil, fmt.Errorf("Cannot add Dockerfile to context: %v", err)
	}
	if _, err := buildImageFromContext(image, ctx, false); err != nil {
		return nil, fmt.Errorf("failed building file storage container image: %v", err)
	}

	// Start the container
	runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--name", container, image)
	if out, ec, err := runCommandWithOutput(runCmd); err != nil {
		return nil, fmt.Errorf("failed to start file storage container. ec=%v\nout=%s\nerr=%v", ec, out, err)
	}

	// Find out the system assigned port
	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "port", container, "80/tcp"))
	if err != nil {
		return nil, fmt.Errorf("failed to find container port: err=%v\nout=%s", err, out)
	}

	return &remoteFileServer{
		container: container,
		image:     image,
		host:      strings.Trim(out, "\n"),
		ctx:       ctx}, nil
}
開發者ID:bkeyoumarsi,項目名稱:docker,代碼行數:33,代碼來源:docker_utils.go

示例2: RandomTmpDirPath

// RandomTmpDirPath provides a temporary path with rand string appended.
// does not create or checks if it exists.
func RandomTmpDirPath(s string) string {
	tmp := "/tmp"
	if runtime.GOOS == "windows" {
		tmp = os.Getenv("TEMP")
	}
	return filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10)))
}
開發者ID:ai-traders,項目名稱:docker,代碼行數:9,代碼來源:utils.go

示例3: TestTagInvalidPrefixedRepo

// ensure we don't allow the use of invalid tags; these tag operations should fail
func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) {
	longTag := stringutils.GenerateRandomAlphaOnlyString(121)

	invalidTags := []string{"repo:fo$z$", "repo:[email protected]", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}

	for _, repotag := range invalidTags {
		out, _, err := dockerCmdWithError("tag", "busybox", repotag)
		c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repotag, out))
	}
}
開發者ID:CadeLaRen,項目名稱:docker-3,代碼行數:11,代碼來源:docker_cli_tag_test.go

示例4: RandomTmpDirPath

// RandomTmpDirPath provides a temporary path with rand string appended.
// does not create or checks if it exists.
func RandomTmpDirPath(s string, platform string) string {
	tmp := "/tmp"
	if platform == "windows" {
		tmp = os.Getenv("TEMP")
	}
	path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10)))
	if platform == "windows" {
		return filepath.FromSlash(path) // Using \
	}
	return filepath.ToSlash(path) // Using /
}
開發者ID:CWSpear,項目名稱:docker,代碼行數:13,代碼來源:utils.go

示例5: TestTagInvalidPrefixedRepo

// ensure we don't allow the use of invalid tags; these tag operations should fail
func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) {
	longTag := stringutils.GenerateRandomAlphaOnlyString(121)

	invalidTags := []string{"repo:fo$z$", "repo:[email protected]", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}

	for _, repotag := range invalidTags {
		_, _, err := dockerCmdWithError("tag", "busybox", repotag)
		if err == nil {
			c.Fatalf("tag busybox %v should have failed", repotag)
		}
	}
}
開發者ID:nixuw,項目名稱:docker,代碼行數:13,代碼來源:docker_cli_tag_test.go

示例6: newRemoteFileServer

func newRemoteFileServer(c *check.C, ctx *FakeContext) *remoteFileServer {
	var (
		image     = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
		container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
	)

	c.Assert(ensureHTTPServerImage(), checker.IsNil)

	// Build the image
	fakeContextAddDockerfile(c, ctx, `FROM httpserver
COPY . /static`)
	buildImageSuccessfully(c, image, withoutCache, withExternalBuildContext(ctx))

	// Start the container
	dockerCmd(c, "run", "-d", "-P", "--name", container, image)

	// Find out the system assigned port
	out, _ := dockerCmd(c, "port", container, "80/tcp")
	fileserverHostPort := strings.Trim(out, "\n")
	_, port, err := net.SplitHostPort(fileserverHostPort)
	if err != nil {
		c.Fatalf("unable to parse file server host:port: %v", err)
	}

	dockerHostURL, err := url.Parse(daemonHost())
	if err != nil {
		c.Fatalf("unable to parse daemon host URL: %v", err)
	}

	host, _, err := net.SplitHostPort(dockerHostURL.Host)
	if err != nil {
		c.Fatalf("unable to parse docker daemon host:port: %v", err)
	}

	return &remoteFileServer{
		container: container,
		image:     image,
		host:      fmt.Sprintf("%s:%s", host, port),
		ctx:       ctx}
}
開發者ID:jfrazelle,項目名稱:docker,代碼行數:40,代碼來源:docker_utils_test.go

示例7: TestInitializeCannotStatPathFileNameTooLong

// os.Stat(v.Path) is NOT returning ErrNotExist so skip and return error from
// initialize
func TestInitializeCannotStatPathFileNameTooLong(t *testing.T) {
	// ENAMETOOLONG
	v := &Volume{Path: stringutils.GenerateRandomAlphaOnlyString(300)}

	err := v.initialize()
	if err == nil {
		t.Fatal("Expected not to initialize volume with a non existent path")
	}

	if !strings.Contains(err.Error(), "file name too long") {
		t.Fatalf("Expected to get ENAMETOOLONG error, got %s", err)
	}
}
開發者ID:nicholaskh,項目名稱:docker,代碼行數:15,代碼來源:volume_test.go

示例8: TestInitializeCannotStatPathFileNameTooLong

// os.Stat(v.Path) is NOT returning ErrNotExist so skip and return error from
// initialize
func TestInitializeCannotStatPathFileNameTooLong(t *testing.T) {
	// ENAMETOOLONG
	v := &Volume{Path: stringutils.GenerateRandomAlphaOnlyString(300)}

	err := v.initialize()
	if err == nil {
		t.Fatal("Expected not to initialize volume with a non existent path")
	}

	if os.IsNotExist(err) {
		t.Fatal("Expected to not get ErrNotExist")
	}
}
開發者ID:colebrumley,項目名稱:docker,代碼行數:15,代碼來源:volume_test.go

示例9: TestTagInvalidPrefixedRepo

// ensure we don't allow the use of invalid tags; these tag operations should fail
func TestTagInvalidPrefixedRepo(t *testing.T) {
	longTag := stringutils.GenerateRandomAlphaOnlyString(121)

	invalidTags := []string{"repo:fo$z$", "repo:[email protected]", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}

	for _, repotag := range invalidTags {
		tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag)
		_, _, err := runCommandWithOutput(tagCmd)
		if err == nil {
			t.Fatalf("tag busybox %v should have failed", repotag)
		}
	}
	logDone("tag - busybox with invalid repo:tagnames --> must not work")
}
開發者ID:jankeromnes,項目名稱:docker,代碼行數:15,代碼來源:docker_cli_tag_test.go

示例10: randomUnixTmpDirPath

// randomUnixTmpDirPath provides a temporary unix path with rand string appended.
// does not create or checks if it exists.
func randomUnixTmpDirPath(s string) string {
	return path.Join("/tmp", fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10)))
}
開發者ID:paultag,項目名稱:docker,代碼行數:5,代碼來源:utils.go


注:本文中的github.com/docker/docker/pkg/stringutils.GenerateRandomAlphaOnlyString函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。