{"action":"created","comment":{"url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/comments/26997411","id":26997411,"diff_hunk":"@@ -127,6 +129,61 @@ type Client struct {\n \texpectedAPIVersion  APIVersion\n }\n \n+// NewClientFromEnv Returns a Client instance configured using\n+// environment variables according to the same logic as the\n+// official Docker client. It will use the latest remote API version\n+// available in the server.\n+func NewClientFromEnv() (*Client, error) {\n+\tclient, err := NewVersionedClientFromEnv(\"\")\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tclient.SkipServerVersionCheck = true\n+\treturn client, nil\n+}\n+\n+// NewVersionedClientFromEnv Returns a Client instance configured using\n+// environment variables according to the same logic as the\n+// official Docker client, using a specific remote API version.\n+func NewVersionedClientFromEnv(apiVersionString string) (*Client, error) {\n+\tdockerHost := os.Getenv(\"DOCKER_HOST\")\n+\tif dockerHost == \"\" {\n+\t\treturn nil, errors.New(\"DOCKER_HOST must be set\")\n+\t}\n+\tif os.Getenv(\"DOCKER_TLS_VERIFY\") == \"\" {\n+\t\treturn NewVersionedClient(dockerHost, apiVersionString)\n+\t}\n+\tparts := strings.SplitN(dockerHost, \"://\", 2)\n+\tif len(parts) != 2 {\n+\t\treturn nil, fmt.Errorf(\"could not split %s into two parts by ://\", dockerHost)\n+\t}\n+\tdockerHost = fmt.Sprintf(\"https://%s\", parts[1])\n+\tdockerCertPath := os.Getenv(\"DOCKER_CERT_PATH\")\n+\tif dockerCertPath == \"\" {\n+\t\thome := os.Getenv(\"HOME\")\n+\t\tif home == \"\" {\n+\t\t\treturn nil, errors.New(\"HOME must be set if DOCKER_TLS_VERIFY is set and DOCKER_CERT_PATH is not set\")\n+\t\t}\n+\t\tdockerCertPath = filepath.Join(home, \".docker\")\n+\t}\n+\tif err := checkFileExists(dockerCertPath); err != nil {","path":"client.go","position":50,"original_position":50,"commit_id":"a9ba241b646fe89038d9b3c5a8512add1b30f875","original_commit_id":"a9ba241b646fe89038d9b3c5a8512add1b30f875","user":{"login":"peter-edge","id":4228796,"avatar_url":"https://avatars.githubusercontent.com/u/4228796?v=3","gravatar_id":"","url":"https://api.github.com/users/peter-edge","html_url":"https://github.com/peter-edge","followers_url":"https://api.github.com/users/peter-edge/followers","following_url":"https://api.github.com/users/peter-edge/following{/other_user}","gists_url":"https://api.github.com/users/peter-edge/gists{/gist_id}","starred_url":"https://api.github.com/users/peter-edge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peter-edge/subscriptions","organizations_url":"https://api.github.com/users/peter-edge/orgs","repos_url":"https://api.github.com/users/peter-edge/repos","events_url":"https://api.github.com/users/peter-edge/events{/privacy}","received_events_url":"https://api.github.com/users/peter-edge/received_events","type":"User","site_admin":false},"body":"You may do this somewhere else, so this might also be redundant.","created_at":"2015-03-24T01:28:18Z","updated_at":"2015-03-24T01:28:18Z","html_url":"https://github.com/fsouza/go-dockerclient/pull/242#discussion_r26997411","pull_request_url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242","_links":{"self":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/comments/26997411"},"html":{"href":"https://github.com/fsouza/go-dockerclient/pull/242#discussion_r26997411"},"pull_request":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242"}}},"pull_request":{"url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242","id":31789959,"html_url":"https://github.com/fsouza/go-dockerclient/pull/242","diff_url":"https://github.com/fsouza/go-dockerclient/pull/242.diff","patch_url":"https://github.com/fsouza/go-dockerclient/pull/242.patch","issue_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/242","number":242,"state":"open","locked":false,"title":"NewClientFromEnv, NewVersionedClientFromEnv mirroring official Docker client","user":{"login":"peter-edge","id":4228796,"avatar_url":"https://avatars.githubusercontent.com/u/4228796?v=3","gravatar_id":"","url":"https://api.github.com/users/peter-edge","html_url":"https://github.com/peter-edge","followers_url":"https://api.github.com/users/peter-edge/followers","following_url":"https://api.github.com/users/peter-edge/following{/other_user}","gists_url":"https://api.github.com/users/peter-edge/gists{/gist_id}","starred_url":"https://api.github.com/users/peter-edge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peter-edge/subscriptions","organizations_url":"https://api.github.com/users/peter-edge/orgs","repos_url":"https://api.github.com/users/peter-edge/repos","events_url":"https://api.github.com/users/peter-edge/events{/privacy}","received_events_url":"https://api.github.com/users/peter-edge/received_events","type":"User","site_admin":false},"body":"I've had this in my own code for a while and thought I'd share it across. It's essentially a direct port of https://github.com/docker/compose/blob/master/compose/cli/docker_client.py and I've been using it for a long time for non-TLS and TLS clients.\r\n\r\nIf it's something you'd accept, I can add tests if necessary, but looking at how the tests are setup now, additional tests may be redundant.","created_at":"2015-03-24T01:24:51Z","updated_at":"2015-03-24T01:28:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d665ce51f37049cf3cc1aeca615e9b7d06f47a5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242/commits","review_comments_url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242/comments","review_comment_url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/242/comments","statuses_url":"https://api.github.com/repos/fsouza/go-dockerclient/statuses/a9ba241b646fe89038d9b3c5a8512add1b30f875","head":{"label":"peter-edge:master","ref":"master","sha":"a9ba241b646fe89038d9b3c5a8512add1b30f875","user":{"login":"peter-edge","id":4228796,"avatar_url":"https://avatars.githubusercontent.com/u/4228796?v=3","gravatar_id":"","url":"https://api.github.com/users/peter-edge","html_url":"https://github.com/peter-edge","followers_url":"https://api.github.com/users/peter-edge/followers","following_url":"https://api.github.com/users/peter-edge/following{/other_user}","gists_url":"https://api.github.com/users/peter-edge/gists{/gist_id}","starred_url":"https://api.github.com/users/peter-edge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peter-edge/subscriptions","organizations_url":"https://api.github.com/users/peter-edge/orgs","repos_url":"https://api.github.com/users/peter-edge/repos","events_url":"https://api.github.com/users/peter-edge/events{/privacy}","received_events_url":"https://api.github.com/users/peter-edge/received_events","type":"User","site_admin":false},"repo":{"id":32747404,"name":"go-dockerclient","full_name":"peter-edge/go-dockerclient","owner":{"login":"peter-edge","id":4228796,"avatar_url":"https://avatars.githubusercontent.com/u/4228796?v=3","gravatar_id":"","url":"https://api.github.com/users/peter-edge","html_url":"https://github.com/peter-edge","followers_url":"https://api.github.com/users/peter-edge/followers","following_url":"https://api.github.com/users/peter-edge/following{/other_user}","gists_url":"https://api.github.com/users/peter-edge/gists{/gist_id}","starred_url":"https://api.github.com/users/peter-edge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peter-edge/subscriptions","organizations_url":"https://api.github.com/users/peter-edge/orgs","repos_url":"https://api.github.com/users/peter-edge/repos","events_url":"https://api.github.com/users/peter-edge/events{/privacy}","received_events_url":"https://api.github.com/users/peter-edge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peter-edge/go-dockerclient","description":"Go HTTP client for the Docker remote API.","fork":true,"url":"https://api.github.com/repos/peter-edge/go-dockerclient","forks_url":"https://api.github.com/repos/peter-edge/go-dockerclient/forks","keys_url":"https://api.github.com/repos/peter-edge/go-dockerclient/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peter-edge/go-dockerclient/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peter-edge/go-dockerclient/teams","hooks_url":"https://api.github.com/repos/peter-edge/go-dockerclient/hooks","issue_events_url":"https://api.github.com/repos/peter-edge/go-dockerclient/issues/events{/number}","events_url":"https://api.github.com/repos/peter-edge/go-dockerclient/events","assignees_url":"https://api.github.com/repos/peter-edge/go-dockerclient/assignees{/user}","branches_url":"https://api.github.com/repos/peter-edge/go-dockerclient/branches{/branch}","tags_url":"https://api.github.com/repos/peter-edge/go-dockerclient/tags","blobs_url":"https://api.github.com/repos/peter-edge/go-dockerclient/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peter-edge/go-dockerclient/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peter-edge/go-dockerclient/git/refs{/sha}","trees_url":"https://api.github.com/repos/peter-edge/go-dockerclient/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peter-edge/go-dockerclient/statuses/{sha}","languages_url":"https://api.github.com/repos/peter-edge/go-dockerclient/languages","stargazers_url":"https://api.github.com/repos/peter-edge/go-dockerclient/stargazers","contributors_url":"https://api.github.com/repos/peter-edge/go-dockerclient/contributors","subscribers_url":"https://api.github.com/repos/peter-edge/go-dockerclient/subscribers","subscription_url":"https://api.github.com/repos/peter-edge/go-dockerclient/subscription","commits_url":"https://api.github.com/repos/peter-edge/go-dockerclient/commits{/sha}","git_commits_url":"https://api.github.com/repos/peter-edge/go-dockerclient/git/commits{/sha}","comments_url":"https://api.github.com/repos/peter-edge/go-dockerclient/comments{/number}","issue_comment_url":"https://api.github.com/repos/peter-edge/go-dockerclient/issues/comments{/number}","contents_url":"https://api.github.com/repos/peter-edge/go-dockerclient/contents/{+path}","compare_url":"https://api.github.com/repos/peter-edge/go-dockerclient/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peter-edge/go-dockerclient/merges","archive_url":"https://api.github.com/repos/peter-edge/go-dockerclient/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peter-edge/go-dockerclient/downloads","issues_url":"https://api.github.com/repos/peter-edge/go-dockerclient/issues{/number}","pulls_url":"https://api.github.com/repos/peter-edge/go-dockerclient/pulls{/number}","milestones_url":"https://api.github.com/repos/peter-edge/go-dockerclient/milestones{/number}","notifications_url":"https://api.github.com/repos/peter-edge/go-dockerclient/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peter-edge/go-dockerclient/labels{/name}","releases_url":"https://api.github.com/repos/peter-edge/go-dockerclient/releases{/id}","created_at":"2015-03-23T17:23:22Z","updated_at":"2015-03-24T01:22:14Z","pushed_at":"2015-03-24T01:22:14Z","git_url":"git://github.com/peter-edge/go-dockerclient.git","ssh_url":"git@github.com:peter-edge/go-dockerclient.git","clone_url":"https://github.com/peter-edge/go-dockerclient.git","svn_url":"https://github.com/peter-edge/go-dockerclient","homepage":"http://godoc.org/github.com/fsouza/go-dockerclient","size":3021,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fsouza:master","ref":"master","sha":"ddb122d10f547ee6cfc4ea7debff407d80abdabc","user":{"login":"fsouza","id":108725,"avatar_url":"https://avatars.githubusercontent.com/u/108725?v=3","gravatar_id":"","url":"https://api.github.com/users/fsouza","html_url":"https://github.com/fsouza","followers_url":"https://api.github.com/users/fsouza/followers","following_url":"https://api.github.com/users/fsouza/following{/other_user}","gists_url":"https://api.github.com/users/fsouza/gists{/gist_id}","starred_url":"https://api.github.com/users/fsouza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsouza/subscriptions","organizations_url":"https://api.github.com/users/fsouza/orgs","repos_url":"https://api.github.com/users/fsouza/repos","events_url":"https://api.github.com/users/fsouza/events{/privacy}","received_events_url":"https://api.github.com/users/fsouza/received_events","type":"User","site_admin":false},"repo":{"id":9998516,"name":"go-dockerclient","full_name":"fsouza/go-dockerclient","owner":{"login":"fsouza","id":108725,"avatar_url":"https://avatars.githubusercontent.com/u/108725?v=3","gravatar_id":"","url":"https://api.github.com/users/fsouza","html_url":"https://github.com/fsouza","followers_url":"https://api.github.com/users/fsouza/followers","following_url":"https://api.github.com/users/fsouza/following{/other_user}","gists_url":"https://api.github.com/users/fsouza/gists{/gist_id}","starred_url":"https://api.github.com/users/fsouza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsouza/subscriptions","organizations_url":"https://api.github.com/users/fsouza/orgs","repos_url":"https://api.github.com/users/fsouza/repos","events_url":"https://api.github.com/users/fsouza/events{/privacy}","received_events_url":"https://api.github.com/users/fsouza/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fsouza/go-dockerclient","description":"Go HTTP client for the Docker remote API.","fork":false,"url":"https://api.github.com/repos/fsouza/go-dockerclient","forks_url":"https://api.github.com/repos/fsouza/go-dockerclient/forks","keys_url":"https://api.github.com/repos/fsouza/go-dockerclient/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fsouza/go-dockerclient/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fsouza/go-dockerclient/teams","hooks_url":"https://api.github.com/repos/fsouza/go-dockerclient/hooks","issue_events_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/events{/number}","events_url":"https://api.github.com/repos/fsouza/go-dockerclient/events","assignees_url":"https://api.github.com/repos/fsouza/go-dockerclient/assignees{/user}","branches_url":"https://api.github.com/repos/fsouza/go-dockerclient/branches{/branch}","tags_url":"https://api.github.com/repos/fsouza/go-dockerclient/tags","blobs_url":"https://api.github.com/repos/fsouza/go-dockerclient/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fsouza/go-dockerclient/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fsouza/go-dockerclient/git/refs{/sha}","trees_url":"https://api.github.com/repos/fsouza/go-dockerclient/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fsouza/go-dockerclient/statuses/{sha}","languages_url":"https://api.github.com/repos/fsouza/go-dockerclient/languages","stargazers_url":"https://api.github.com/repos/fsouza/go-dockerclient/stargazers","contributors_url":"https://api.github.com/repos/fsouza/go-dockerclient/contributors","subscribers_url":"https://api.github.com/repos/fsouza/go-dockerclient/subscribers","subscription_url":"https://api.github.com/repos/fsouza/go-dockerclient/subscription","commits_url":"https://api.github.com/repos/fsouza/go-dockerclient/commits{/sha}","git_commits_url":"https://api.github.com/repos/fsouza/go-dockerclient/git/commits{/sha}","comments_url":"https://api.github.com/repos/fsouza/go-dockerclient/comments{/number}","issue_comment_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/comments{/number}","contents_url":"https://api.github.com/repos/fsouza/go-dockerclient/contents/{+path}","compare_url":"https://api.github.com/repos/fsouza/go-dockerclient/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fsouza/go-dockerclient/merges","archive_url":"https://api.github.com/repos/fsouza/go-dockerclient/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fsouza/go-dockerclient/downloads","issues_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues{/number}","pulls_url":"https://api.github.com/repos/fsouza/go-dockerclient/pulls{/number}","milestones_url":"https://api.github.com/repos/fsouza/go-dockerclient/milestones{/number}","notifications_url":"https://api.github.com/repos/fsouza/go-dockerclient/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fsouza/go-dockerclient/labels{/name}","releases_url":"https://api.github.com/repos/fsouza/go-dockerclient/releases{/id}","created_at":"2013-05-11T11:21:31Z","updated_at":"2015-03-23T03:36:54Z","pushed_at":"2015-03-24T01:24:52Z","git_url":"git://github.com/fsouza/go-dockerclient.git","ssh_url":"git@github.com:fsouza/go-dockerclient.git","clone_url":"https://github.com/fsouza/go-dockerclient.git","svn_url":"https://github.com/fsouza/go-dockerclient","homepage":"http://godoc.org/github.com/fsouza/go-dockerclient","size":3021,"stargazers_count":293,"watchers_count":293,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":133,"mirror_url":null,"open_issues_count":21,"forks":133,"open_issues":21,"watchers":293,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242"},"html":{"href":"https://github.com/fsouza/go-dockerclient/pull/242"},"issue":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/issues/242"},"comments":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/issues/242/comments"},"review_comments":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242/comments"},"review_comment":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/pulls/242/commits"},"statuses":{"href":"https://api.github.com/repos/fsouza/go-dockerclient/statuses/a9ba241b646fe89038d9b3c5a8512add1b30f875"}}}}