{"action":"created","comment":{"url":"https://api.github.com/repos/docker/distribution/pulls/comments/36957633","id":36957633,"diff_hunk":"@@ -0,0 +1,378 @@\n+package speedy\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"io/ioutil\"\n+\t\"net/http\"\n+\t\"sort\"\n+\t\"strings\"\n+\t\"time\"\n+)\n+\n+//Client is the client for speedy.\n+type Client struct {\n+}\n+\n+//MetaInfoValue is meta info format of speedy.\n+type MetaInfoValue struct {\n+\tIndex   uint64\n+\tStart   uint64\n+\tEnd     uint64\n+\tIsLast  bool\n+\tIsDir   bool `json:\",omitempty\"`\n+\tModTime time.Time\n+}\n+\n+//OrderByIndex is Used to sort metainfo by index\n+//E.g. we may get a metainfo array for a special path, so we need to sort this metainfo array.\n+type OrderByIndex []*MetaInfoValue\n+\n+const (\n+\theaderSourcePath = \"Source-Path\"\n+\theaderDestPath   = \"Dest-Path\"\n+\theaderPath       = \"Path\"\n+\theaderIndex      = \"Fragment-Index\"\n+\theaderRange      = \"Bytes-Range\"\n+\theaderIsLast     = \"Is-Last\"\n+\theaderVersion    = \"Registry-Version\"\n+\tfragmentInfo     = \"fragment-info\"\n+\tfileList         = \"file-list\"\n+\tpathDescendant   = \"path-descendant\"\n+)\n+\n+func (a OrderByIndex) Len() int {\n+\treturn len(a)\n+}\n+\n+func (a OrderByIndex) Swap(i, j int) {\n+\ta[i], a[j] = a[j], a[i]\n+}\n+\n+func (a OrderByIndex) Less(i, j int) bool {\n+\treturn a[i].Index < a[j].Index\n+}\n+\n+func (c *Client) doRequest(req *http.Request) ([]byte, int, error) {\n+\tclient := &http.Client{}\n+\tresp, err := client.Do(req)\n+\tif err != nil {\n+\t\tif resp != nil {\n+\t\t\treturn nil, resp.StatusCode, err\n+\t\t}\n+\t\treturn nil, http.StatusNotFound, err\n+\t}\n+\n+\tdataBody, err := ioutil.ReadAll(resp.Body)\n+\tdefer resp.Body.Close()\n+\tif err != nil {\n+\t\treturn nil, resp.StatusCode, err\n+\t}\n+\treturn dataBody, resp.StatusCode, nil\n+}\n+\n+func (c *Client) getMetaInfoValueFromJSON(data []byte) ([]*MetaInfoValue, error) {\n+\tvar mapResult map[string]interface{}\n+\terr := json.Unmarshal(data, &mapResult)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tfragmentInfoValue, ok := mapResult[fragmentInfo]\n+\tif !ok {\n+\t\treturn nil, fmt.Errorf(\"Response format maybe error: %v\", mapResult)\n+\t}\n+\n+\tinfoArr, ok := fragmentInfoValue.([]interface{})\n+\tif !ok {\n+\t\treturn nil, fmt.Errorf(\"Response format maybe error, value is not a array: %v\", fragmentInfoValue)\n+\t}\n+\n+\tvar result []*MetaInfoValue\n+\tfor _, info := range infoArr {\n+\t\tm, ok := info.(map[string]interface{})\n+\t\tif !ok {\n+\t\t\treturn nil, fmt.Errorf(\"Response format maybe error, infoArr: %v\", infoArr)\n+\t\t}\n+\n+\t\tmiv := new(MetaInfoValue)\n+\t\tindex, ok := m[\"Index\"].(float64)\n+\t\tif !ok {\n+\t\t\treturn nil, fmt.Errorf(\"Response format maybe error, MetaInfoValue: %v\", m)\n+\t\t}\n+\t\tmiv.Index = uint64(index)","path":"registry/storage/driver/speedy/speedyclient.go","position":104,"original_position":104,"commit_id":"70fcd125f16ebb28db2ba56208cb75ce28919a6c","original_commit_id":"70fcd125f16ebb28db2ba56208cb75ce28919a6c","user":{"login":"zhangcoldwater","id":7858264,"avatar_url":"https://avatars.githubusercontent.com/u/7858264?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangcoldwater","html_url":"https://github.com/zhangcoldwater","followers_url":"https://api.github.com/users/zhangcoldwater/followers","following_url":"https://api.github.com/users/zhangcoldwater/following{/other_user}","gists_url":"https://api.github.com/users/zhangcoldwater/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangcoldwater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangcoldwater/subscriptions","organizations_url":"https://api.github.com/users/zhangcoldwater/orgs","repos_url":"https://api.github.com/users/zhangcoldwater/repos","events_url":"https://api.github.com/users/zhangcoldwater/events{/privacy}","received_events_url":"https://api.github.com/users/zhangcoldwater/received_events","type":"User","site_admin":false},"body":"\n\nindex is uint64, \nbut json.Marshal will change int(int64 and so on) to float64\nso the int value in the result of json.Unmarshal is float64\n\n\nfor example:\npackage main\n\n\nimport (\n\"encoding/json\"\n\"fmt\"\n)\n\n\ntype Test struct {\nIndex int\nStart int\n}\n\n\nfunc main() {\nt := &Test{\nIndex: int(10),\nStart: int(11),\n}\nfmt.Println(t)\n\n\nbyteResult, err := json.Marshal(t)\nif err != nil {\nfmt.Println(err)\nreturn\n}\n\n\nfmt.Println(\"result:\", byteResult)\n\n\nvar m map[string]interface{}\nerr = json.Unmarshal(byteResult, &m)\nif err != nil {\nfmt.Println(err)\nreturn\n}\nfmt.Println(m)\n\n\nindex, ok := m[\"Index\"].(float64)\nif !ok {\nfmt.Println(\"the type of m[index] is not float64\")\nreturn\n}\nfmt.Println(\"the type of m[index] is float64\")\nfmt.Println(index)\n\n\nindex2, ok := m[\"Index\"].(int)\nif !ok {\nfmt.Println(\"the type of m[index] is not int\")\nreturn\n}\nfmt.Println(index2)\n}\n\n\n\n\n--\n\n\nAt 2015-08-12 06:39:16, \"Anton Tyurin\" <notifications@github.com> wrote:\n\n\nIn registry/storage/driver/speedy/speedyclient.go:\n\n> +\t\treturn nil, fmt.Errorf(\"Response format maybe error, value is not a array: %v\", fragmentInfoValue)\n> +\t}\n> +\n> +\tvar result []*MetaInfoValue\n> +\tfor _, info := range infoArr {\n> +\t\tm, ok := info.(map[string]interface{})\n> +\t\tif !ok {\n> +\t\t\treturn nil, fmt.Errorf(\"Response format maybe error, infoArr: %v\", infoArr)\n> +\t\t}\n> +\n> +\t\tmiv := new(MetaInfoValue)\n> +\t\tindex, ok := m[\"Index\"].(float64)\n> +\t\tif !ok {\n> +\t\t\treturn nil, fmt.Errorf(\"Response format maybe error, MetaInfoValue: %v\", m)\n> +\t\t}\n> +\t\tmiv.Index = uint64(index)\n\n\nIs index float64 or uint64? What's the point of casting to float64 & to uint64?\n\n—\nReply to this email directly or view it on GitHub.","created_at":"2015-08-13T09:52:07Z","updated_at":"2015-08-13T09:52:07Z","html_url":"https://github.com/docker/distribution/pull/685#discussion_r36957633","pull_request_url":"https://api.github.com/repos/docker/distribution/pulls/685","_links":{"self":{"href":"https://api.github.com/repos/docker/distribution/pulls/comments/36957633"},"html":{"href":"https://github.com/docker/distribution/pull/685#discussion_r36957633"},"pull_request":{"href":"https://api.github.com/repos/docker/distribution/pulls/685"}}},"pull_request":{"url":"https://api.github.com/repos/docker/distribution/pulls/685","id":39568537,"html_url":"https://github.com/docker/distribution/pull/685","diff_url":"https://github.com/docker/distribution/pull/685.diff","patch_url":"https://github.com/docker/distribution/pull/685.patch","issue_url":"https://api.github.com/repos/docker/distribution/issues/685","number":685,"state":"open","locked":false,"title":"Add a storage-driver for speedy","user":{"login":"zhangcoldwater","id":7858264,"avatar_url":"https://avatars.githubusercontent.com/u/7858264?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangcoldwater","html_url":"https://github.com/zhangcoldwater","followers_url":"https://api.github.com/users/zhangcoldwater/followers","following_url":"https://api.github.com/users/zhangcoldwater/following{/other_user}","gists_url":"https://api.github.com/users/zhangcoldwater/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangcoldwater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangcoldwater/subscriptions","organizations_url":"https://api.github.com/users/zhangcoldwater/orgs","repos_url":"https://api.github.com/users/zhangcoldwater/repos","events_url":"https://api.github.com/users/zhangcoldwater/events{/privacy}","received_events_url":"https://api.github.com/users/zhangcoldwater/received_events","type":"User","site_admin":false},"body":"Add a storage-driver for speedy.\r\nSpeedy(https://github.com/jcloudpub/speedy) is a high performance distributed docker image storage solution written by go/c.  \r\nAfter testing, this driver works well with docker-1.6, distribution and speedy.","created_at":"2015-07-09T10:26:34Z","updated_at":"2015-08-13T09:52:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e9607fb07a5a4a30c2fbf2003ae15060232e2748","assignee":{"login":"aaronlehmann","id":10601430,"avatar_url":"https://avatars.githubusercontent.com/u/10601430?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronlehmann","html_url":"https://github.com/aaronlehmann","followers_url":"https://api.github.com/users/aaronlehmann/followers","following_url":"https://api.github.com/users/aaronlehmann/following{/other_user}","gists_url":"https://api.github.com/users/aaronlehmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronlehmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronlehmann/subscriptions","organizations_url":"https://api.github.com/users/aaronlehmann/orgs","repos_url":"https://api.github.com/users/aaronlehmann/repos","events_url":"https://api.github.com/users/aaronlehmann/events{/privacy}","received_events_url":"https://api.github.com/users/aaronlehmann/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/docker/distribution/pulls/685/commits","review_comments_url":"https://api.github.com/repos/docker/distribution/pulls/685/comments","review_comment_url":"https://api.github.com/repos/docker/distribution/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/distribution/issues/685/comments","statuses_url":"https://api.github.com/repos/docker/distribution/statuses/70fcd125f16ebb28db2ba56208cb75ce28919a6c","head":{"label":"zhangcoldwater:master","ref":"master","sha":"70fcd125f16ebb28db2ba56208cb75ce28919a6c","user":{"login":"zhangcoldwater","id":7858264,"avatar_url":"https://avatars.githubusercontent.com/u/7858264?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangcoldwater","html_url":"https://github.com/zhangcoldwater","followers_url":"https://api.github.com/users/zhangcoldwater/followers","following_url":"https://api.github.com/users/zhangcoldwater/following{/other_user}","gists_url":"https://api.github.com/users/zhangcoldwater/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangcoldwater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangcoldwater/subscriptions","organizations_url":"https://api.github.com/users/zhangcoldwater/orgs","repos_url":"https://api.github.com/users/zhangcoldwater/repos","events_url":"https://api.github.com/users/zhangcoldwater/events{/privacy}","received_events_url":"https://api.github.com/users/zhangcoldwater/received_events","type":"User","site_admin":false},"repo":{"id":38793440,"name":"distribution","full_name":"zhangcoldwater/distribution","owner":{"login":"zhangcoldwater","id":7858264,"avatar_url":"https://avatars.githubusercontent.com/u/7858264?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangcoldwater","html_url":"https://github.com/zhangcoldwater","followers_url":"https://api.github.com/users/zhangcoldwater/followers","following_url":"https://api.github.com/users/zhangcoldwater/following{/other_user}","gists_url":"https://api.github.com/users/zhangcoldwater/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangcoldwater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangcoldwater/subscriptions","organizations_url":"https://api.github.com/users/zhangcoldwater/orgs","repos_url":"https://api.github.com/users/zhangcoldwater/repos","events_url":"https://api.github.com/users/zhangcoldwater/events{/privacy}","received_events_url":"https://api.github.com/users/zhangcoldwater/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zhangcoldwater/distribution","description":"The Docker toolset to pack, ship, store, and deliver content","fork":true,"url":"https://api.github.com/repos/zhangcoldwater/distribution","forks_url":"https://api.github.com/repos/zhangcoldwater/distribution/forks","keys_url":"https://api.github.com/repos/zhangcoldwater/distribution/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zhangcoldwater/distribution/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zhangcoldwater/distribution/teams","hooks_url":"https://api.github.com/repos/zhangcoldwater/distribution/hooks","issue_events_url":"https://api.github.com/repos/zhangcoldwater/distribution/issues/events{/number}","events_url":"https://api.github.com/repos/zhangcoldwater/distribution/events","assignees_url":"https://api.github.com/repos/zhangcoldwater/distribution/assignees{/user}","branches_url":"https://api.github.com/repos/zhangcoldwater/distribution/branches{/branch}","tags_url":"https://api.github.com/repos/zhangcoldwater/distribution/tags","blobs_url":"https://api.github.com/repos/zhangcoldwater/distribution/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zhangcoldwater/distribution/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zhangcoldwater/distribution/git/refs{/sha}","trees_url":"https://api.github.com/repos/zhangcoldwater/distribution/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zhangcoldwater/distribution/statuses/{sha}","languages_url":"https://api.github.com/repos/zhangcoldwater/distribution/languages","stargazers_url":"https://api.github.com/repos/zhangcoldwater/distribution/stargazers","contributors_url":"https://api.github.com/repos/zhangcoldwater/distribution/contributors","subscribers_url":"https://api.github.com/repos/zhangcoldwater/distribution/subscribers","subscription_url":"https://api.github.com/repos/zhangcoldwater/distribution/subscription","commits_url":"https://api.github.com/repos/zhangcoldwater/distribution/commits{/sha}","git_commits_url":"https://api.github.com/repos/zhangcoldwater/distribution/git/commits{/sha}","comments_url":"https://api.github.com/repos/zhangcoldwater/distribution/comments{/number}","issue_comment_url":"https://api.github.com/repos/zhangcoldwater/distribution/issues/comments{/number}","contents_url":"https://api.github.com/repos/zhangcoldwater/distribution/contents/{+path}","compare_url":"https://api.github.com/repos/zhangcoldwater/distribution/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zhangcoldwater/distribution/merges","archive_url":"https://api.github.com/repos/zhangcoldwater/distribution/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zhangcoldwater/distribution/downloads","issues_url":"https://api.github.com/repos/zhangcoldwater/distribution/issues{/number}","pulls_url":"https://api.github.com/repos/zhangcoldwater/distribution/pulls{/number}","milestones_url":"https://api.github.com/repos/zhangcoldwater/distribution/milestones{/number}","notifications_url":"https://api.github.com/repos/zhangcoldwater/distribution/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zhangcoldwater/distribution/labels{/name}","releases_url":"https://api.github.com/repos/zhangcoldwater/distribution/releases{/id}","created_at":"2015-07-09T02:59:01Z","updated_at":"2015-07-09T02:59:02Z","pushed_at":"2015-07-09T15:01:24Z","git_url":"git://github.com/zhangcoldwater/distribution.git","ssh_url":"git@github.com:zhangcoldwater/distribution.git","clone_url":"https://github.com/zhangcoldwater/distribution.git","svn_url":"https://github.com/zhangcoldwater/distribution","homepage":null,"size":2816,"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":"docker:master","ref":"master","sha":"bdcae0597f11ce5ac8b5be8f1c5a56ade7e97b26","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":28366058,"name":"distribution","full_name":"docker/distribution","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/distribution","description":"The Docker toolset to pack, ship, store, and deliver content","fork":false,"url":"https://api.github.com/repos/docker/distribution","forks_url":"https://api.github.com/repos/docker/distribution/forks","keys_url":"https://api.github.com/repos/docker/distribution/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/distribution/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/distribution/teams","hooks_url":"https://api.github.com/repos/docker/distribution/hooks","issue_events_url":"https://api.github.com/repos/docker/distribution/issues/events{/number}","events_url":"https://api.github.com/repos/docker/distribution/events","assignees_url":"https://api.github.com/repos/docker/distribution/assignees{/user}","branches_url":"https://api.github.com/repos/docker/distribution/branches{/branch}","tags_url":"https://api.github.com/repos/docker/distribution/tags","blobs_url":"https://api.github.com/repos/docker/distribution/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/distribution/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/distribution/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/distribution/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/distribution/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/distribution/languages","stargazers_url":"https://api.github.com/repos/docker/distribution/stargazers","contributors_url":"https://api.github.com/repos/docker/distribution/contributors","subscribers_url":"https://api.github.com/repos/docker/distribution/subscribers","subscription_url":"https://api.github.com/repos/docker/distribution/subscription","commits_url":"https://api.github.com/repos/docker/distribution/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/distribution/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/distribution/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/distribution/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/distribution/contents/{+path}","compare_url":"https://api.github.com/repos/docker/distribution/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/distribution/merges","archive_url":"https://api.github.com/repos/docker/distribution/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/distribution/downloads","issues_url":"https://api.github.com/repos/docker/distribution/issues{/number}","pulls_url":"https://api.github.com/repos/docker/distribution/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/distribution/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/distribution/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/distribution/labels{/name}","releases_url":"https://api.github.com/repos/docker/distribution/releases{/id}","created_at":"2014-12-22T23:49:26Z","updated_at":"2015-08-13T08:59:08Z","pushed_at":"2015-08-13T08:59:24Z","git_url":"git://github.com/docker/distribution.git","ssh_url":"git@github.com:docker/distribution.git","clone_url":"https://github.com/docker/distribution.git","svn_url":"https://github.com/docker/distribution","homepage":null,"size":12359,"stargazers_count":859,"watchers_count":859,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":329,"mirror_url":null,"open_issues_count":100,"forks":329,"open_issues":100,"watchers":859,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/distribution/pulls/685"},"html":{"href":"https://github.com/docker/distribution/pull/685"},"issue":{"href":"https://api.github.com/repos/docker/distribution/issues/685"},"comments":{"href":"https://api.github.com/repos/docker/distribution/issues/685/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/distribution/pulls/685/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/distribution/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/distribution/pulls/685/commits"},"statuses":{"href":"https://api.github.com/repos/docker/distribution/statuses/70fcd125f16ebb28db2ba56208cb75ce28919a6c"}}}}