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


Golang registry.NewRegistry函數代碼示例

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


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

示例1: ImagePush

// FIXME: Allow to interupt current push when new push of same image is done.
func (srv *Server) ImagePush(name, endpoint string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
	if err := srv.poolAdd("push", name); err != nil {
		return err
	}
	defer srv.poolRemove("push", name)

	out = utils.NewWriteFlusher(out)
	img, err := srv.runtime.graph.Get(name)
	r, err2 := registry.NewRegistry(srv.runtime.root, authConfig)
	if err2 != nil {
		return err2
	}

	if err != nil {
		out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", name, len(srv.runtime.repositories.Repositories[name])))
		// If it fails, try to get the repository
		if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
			if err := srv.pushRepository(r, out, name, endpoint, localRepo, sf); err != nil {
				return err
			}
			return nil
		}

		return err
	}
	out.Write(sf.FormatStatus("The push refers to an image: [%s]", name))
	if err := srv.pushImage(r, out, name, img.ID, endpoint, nil, sf); err != nil {
		return err
	}
	return nil
}
開發者ID:sjbalaji,項目名稱:docker,代碼行數:32,代碼來源:server.go

示例2: ImagePull

func (srv *Server) ImagePull(name string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
	r, err := registry.NewRegistry(srv.runtime.root, authConfig)
	if err != nil {
		return err
	}
	if err := srv.poolAdd("pull", name+":"+tag); err != nil {
		return err
	}
	defer srv.poolRemove("pull", name+":"+tag)

	// Resolve the Repository name from fqn to endpoint + name
	var endpoint string
	endpoint, name, err = registry.ResolveRepositoryName(name)
	if err != nil {
		return err
	}

	out = utils.NewWriteFlusher(out)
	err = srv.pullRepository(r, out, name, tag, endpoint, sf)
	if err != nil {
		if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
			return err
		}
		return nil
	}

	return nil
}
開發者ID:kmindg,項目名稱:docker,代碼行數:28,代碼來源:server.go

示例3: ImagePull

func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
	r, err := registry.NewRegistry(srv.runtime.root, authConfig)
	if err != nil {
		return err
	}
	if err := srv.poolAdd("pull", name+":"+tag); err != nil {
		return err
	}
	defer srv.poolRemove("pull", name+":"+tag)

	remote := name
	parts := strings.Split(name, "/")
	if len(parts) > 2 {
		remote = fmt.Sprintf("src/%s", url.QueryEscape(strings.Join(parts, "/")))
	}
	out = utils.NewWriteFlusher(out)
	err = srv.pullRepository(r, out, name, remote, tag, endpoint, sf)
	if err != nil && endpoint != "" {
		if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
			return err
		}
		return nil
	}

	return nil
}
開發者ID:sjbalaji,項目名稱:docker,代碼行數:26,代碼來源:server.go

示例4: ImagePull

func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig, metaHeaders map[string][]string, parallel bool) error {
	r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.HTTPRequestFactory(metaHeaders))
	if err != nil {
		return err
	}
	if err := srv.poolAdd("pull", localName+":"+tag); err != nil {
		return err
	}
	defer srv.poolRemove("pull", localName+":"+tag)

	// Resolve the Repository name from fqn to endpoint + name
	endpoint, remoteName, err := registry.ResolveRepositoryName(localName)
	if err != nil {
		return err
	}

	if endpoint == auth.IndexServerAddress() {
		// If pull "index.docker.io/foo/bar", it's stored locally under "foo/bar"
		localName = remoteName
	}

	out = utils.NewWriteFlusher(out)
	err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf, parallel)
	if err == registry.ErrLoginRequired {
		return err
	}
	if err != nil {
		if err := srv.pullImage(r, out, remoteName, endpoint, nil, sf); err != nil {
			return err
		}
		return nil
	}

	return nil
}
開發者ID:silpion,項目名稱:docker,代碼行數:35,代碼來源:server.go

示例5: TestGetImagesSearch

func TestGetImagesSearch(t *testing.T) {
	runtime, err := newTestRuntime()
	if err != nil {
		t.Fatal(err)
	}
	defer nuke(runtime)

	srv := &Server{
		runtime:  runtime,
		registry: registry.NewRegistry(runtime.root),
	}

	r := httptest.NewRecorder()

	req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
	if err != nil {
		t.Fatal(err)
	}

	if err := getImagesSearch(srv, r, req, nil); err != nil {
		t.Fatal(err)
	}

	results := []ApiSearch{}
	if err := json.Unmarshal(r.Body.Bytes(), &results); err != nil {
		t.Fatal(err)
	}
	if len(results) < 2 {
		t.Errorf("Excepted at least 2 lines, %d found", len(results))
	}
}
開發者ID:JioCloud,項目名稱:docker,代碼行數:31,代碼來源:api_test.go

示例6: TestPostAuth

func TestPostAuth(t *testing.T) {
	runtime, err := newTestRuntime()
	if err != nil {
		t.Fatal(err)
	}
	defer nuke(runtime)

	srv := &Server{
		runtime:  runtime,
		registry: registry.NewRegistry(runtime.root),
	}

	authConfigOrig := &auth.AuthConfig{
		Username: "utest",
		Email:    "[email protected]",
	}
	srv.registry.ResetClient(authConfigOrig)

	r := httptest.NewRecorder()
	if err := getAuth(srv, r, nil, nil); err != nil {
		t.Fatal(err)
	}

	authConfig := &auth.AuthConfig{}
	if err := json.Unmarshal(r.Body.Bytes(), authConfig); err != nil {
		t.Fatal(err)
	}

	if authConfig.Username != authConfigOrig.Username || authConfig.Email != authConfigOrig.Email {
		t.Errorf("The retrieve auth mismatch with the one set.")
	}
}
開發者ID:JioCloud,項目名稱:docker,代碼行數:32,代碼來源:api_test.go

示例7: init

func init() {
	// Hack to run sys init during unit testing
	if utils.SelfPath() == "/sbin/init" {
		SysInit()
		return
	}

	if usr, err := user.Current(); err != nil {
		panic(err)
	} else if usr.Uid != "0" {
		panic("docker tests needs to be run as root")
	}

	NetworkBridgeIface = "testdockbr0"

	// Make it our Store root
	runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false)
	if err != nil {
		panic(err)
	}

	// Create the "Server"
	srv := &Server{
		runtime:  runtime,
		registry: registry.NewRegistry(runtime.root),
	}
	// Retrieve the Image
	if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout); err != nil {
		panic(err)
	}
}
開發者ID:JioCloud,項目名稱:docker,代碼行數:31,代碼來源:runtime_test.go

示例8: ImagesSearch

func (srv *Server) ImagesSearch(term string) ([]registry.SearchResult, error) {
	r, err := registry.NewRegistry(srv.runtime.config.Root, nil, srv.HTTPRequestFactory(nil))
	if err != nil {
		return nil, err
	}
	results, err := r.SearchRepositories(term)
	if err != nil {
		return nil, err
	}
	return results.Results, nil
}
開發者ID:juniorz,項目名稱:docker,代碼行數:11,代碼來源:server.go

示例9: NewServer

func NewServer(autoRestart bool) (*Server, error) {
	if runtime.GOARCH != "amd64" {
		log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
	}
	runtime, err := NewRuntime(autoRestart)
	if err != nil {
		return nil, err
	}
	srv := &Server{
		runtime:  runtime,
		registry: registry.NewRegistry(runtime.root),
	}
	runtime.srv = srv
	return srv, nil
}
開發者ID:richardjoo,項目名稱:docker,代碼行數:15,代碼來源:server.go

示例10: ImagePull

func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter) error {
	r := registry.NewRegistry(srv.runtime.root)
	out = utils.NewWriteFlusher(out)
	if endpoint != "" {
		if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
			return err
		}
		return nil
	}

	if err := srv.pullRepository(r, out, name, tag, sf); err != nil {
		return err
	}

	return nil
}
開發者ID:brunoqc,項目名稱:docker,代碼行數:16,代碼來源:server.go

示例11: ImagesSearch

func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {

	results, err := registry.NewRegistry(srv.runtime.root, nil).SearchRepositories(term)
	if err != nil {
		return nil, err
	}

	var outs []APISearch
	for _, repo := range results.Results {
		var out APISearch
		out.Description = repo["description"]
		out.Name = repo["name"]
		outs = append(outs, out)
	}
	return outs, nil
}
開發者ID:kalburgimanjunath,項目名稱:docker,代碼行數:16,代碼來源:server.go

示例12: TestGetAuth

func TestGetAuth(t *testing.T) {
	runtime, err := newTestRuntime()
	if err != nil {
		t.Fatal(err)
	}
	defer nuke(runtime)

	srv := &Server{
		runtime:  runtime,
		registry: registry.NewRegistry(runtime.root),
	}

	r := httptest.NewRecorder()

	authConfig := &auth.AuthConfig{
		Username: "utest",
		Password: "utest",
		Email:    "[email protected]",
	}

	authConfigJson, err := json.Marshal(authConfig)
	if err != nil {
		t.Fatal(err)
	}

	req, err := http.NewRequest("POST", "/auth", bytes.NewReader(authConfigJson))
	if err != nil {
		t.Fatal(err)
	}

	if err := postAuth(srv, r, req, nil); err != nil {
		t.Fatal(err)
	}

	if r.Code != http.StatusOK && r.Code != 0 {
		t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
	}

	newAuthConfig := srv.registry.GetAuthConfig()
	if newAuthConfig.Username != authConfig.Username ||
		newAuthConfig.Email != authConfig.Email {
		t.Fatalf("The auth configuration hasn't been set correctly")
	}
}
開發者ID:JioCloud,項目名稱:docker,代碼行數:44,代碼來源:api_test.go

示例13: ImagePull

func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter) error {
	r := registry.NewRegistry(srv.runtime.root)
	out = utils.NewWriteFlusher(out)
	if endpoint != "" {
		if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
			return err
		}
		return nil
	}
	remote := name
	parts := strings.Split(name, "/")
	if len(parts) > 2 {
		remote = fmt.Sprintf("src/%s", url.QueryEscape(strings.Join(parts, "/")))
	}
	if err := srv.pullRepository(r, out, name, remote, tag, sf); err != nil {
		return err
	}

	return nil
}
開發者ID:hayeah,項目名稱:docker,代碼行數:20,代碼來源:server.go

示例14: ImagePush

// FIXME: Allow to interrupt current push when new push of same image is done.
func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig, metaHeaders map[string][]string) error {
	if err := srv.poolAdd("push", localName); err != nil {
		return err
	}
	defer srv.poolRemove("push", localName)

	// Resolve the Repository name from fqn to endpoint + name
	endpoint, remoteName, err := registry.ResolveRepositoryName(localName)
	if err != nil {
		return err
	}

	out = utils.NewWriteFlusher(out)
	img, err := srv.runtime.graph.Get(localName)
	r, err2 := registry.NewRegistry(srv.runtime.root, authConfig, srv.HTTPRequestFactory(metaHeaders))
	if err2 != nil {
		return err2
	}

	if err != nil {
		reposLen := len(srv.runtime.repositories.Repositories[localName])
		out.Write(sf.FormatStatus("", "The push refers to a repository [%s] (len: %d)", localName, reposLen))
		// If it fails, try to get the repository
		if localRepo, exists := srv.runtime.repositories.Repositories[localName]; exists {
			if err := srv.pushRepository(r, out, localName, remoteName, localRepo, endpoint, sf); err != nil {
				return err
			}
			return nil
		}
		return err
	}

	var token []string
	out.Write(sf.FormatStatus("", "The push refers to an image: [%s]", localName))
	if _, err := srv.pushImage(r, out, remoteName, img.ID, endpoint, token, sf); err != nil {
		return err
	}
	return nil
}
開發者ID:silpion,項目名稱:docker,代碼行數:40,代碼來源:server.go

示例15: ImagePush

func (srv *Server) ImagePush(name, endpoint string, out io.Writer) error {
	out = utils.NewWriteFlusher(out)
	img, err := srv.runtime.graph.Get(name)
	r := registry.NewRegistry(srv.runtime.root)

	if err != nil {
		fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
		// If it fails, try to get the repository
		if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
			if err := srv.pushRepository(r, out, name, localRepo); err != nil {
				return err
			}
			return nil
		}

		return err
	}
	fmt.Fprintf(out, "The push refers to an image: [%s]\n", name)
	if err := srv.pushImage(r, out, name, img.Id, endpoint, nil); err != nil {
		return err
	}
	return nil
}
開發者ID:nemaload,項目名稱:docker,代碼行數:23,代碼來源:server.go


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