{"action":"created","comment":{"url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments/45707224","id":45707224,"diff_hunk":"@@ -0,0 +1,129 @@\n+// -*- Mode: Go; indent-tabs-mode: t -*-\n+\n+/*\n+ * Copyright (C) 2014-2015 Canonical Ltd\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+package client\n+\n+import (\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"net\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\n+\t\"github.com/ubuntu-core/snappy/dirs\"\n+)\n+\n+func unixDialer(_, _ string) (net.Conn, error) {\n+\treturn net.Dial(\"unix\", dirs.SnapdSocket)\n+}\n+\n+type doer interface {\n+\tDo(*http.Request) (*http.Response, error)\n+}\n+\n+// A Client knows how to talk to the snappy daemon\n+type Client struct {\n+\tdoer doer\n+}\n+\n+// New returns a new instance of Client\n+func New() *Client {\n+\ttr := &http.Transport{Dial: unixDialer}\n+\n+\treturn &Client{\n+\t\tdoer: &http.Client{Transport: tr},\n+\t}\n+}\n+\n+// raw performs a request and returns the resulting http.Response and\n+// error you usually only need to call this directly if you expect the\n+// response to not be JSON, otherwise you'd call Do(...) instead.\n+func (client *Client) raw(method, path string, body io.Reader) (*http.Response, error) {\n+\t// fake a url to keep http.Client happy\n+\tu := url.URL{\n+\t\tScheme: \"http\",\n+\t\tHost:   \"localhost\",\n+\t\tPath:   path,\n+\t}\n+\treq, err := http.NewRequest(method, u.String(), body)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\treturn client.doer.Do(req)\n+}\n+\n+// do performs a request and decodes the resulting json into the given\n+// value. It's low-level, for testing/experimenting only; you should\n+// usually use a higher level interface that builds on this.\n+func (client *Client) do(method, path string, body io.Reader, v interface{}) error {\n+\trsp, err := client.raw(method, path, body)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tdefer rsp.Body.Close()\n+\n+\tdec := json.NewDecoder(rsp.Body)\n+\tif err := dec.Decode(v); err != nil {\n+\t\treturn err\n+\t}\n+\n+\treturn nil\n+}\n+\n+// A response produced by the REST API will usually fit in this\n+// (exceptions are the icons/ endpoints obvs)\n+type response struct {\n+\tResult     json.RawMessage `json:\"result\"`\n+\tStatus     string          `json:\"status\"`\n+\tStatusCode int             `json:\"status_code\"`\n+\tType       string          `json:\"type\"`\n+}\n+\n+// SysInfo holds system information\n+type SysInfo struct {","path":"client/client.go","position":101,"original_position":101,"commit_id":"0c7fccb633bfa599837f050c636c2f141ae29d79","original_commit_id":"0c7fccb633bfa599837f050c636c2f141ae29d79","user":{"login":"mvo5","id":914418,"avatar_url":"https://avatars.githubusercontent.com/u/914418?v=3","gravatar_id":"","url":"https://api.github.com/users/mvo5","html_url":"https://github.com/mvo5","followers_url":"https://api.github.com/users/mvo5/followers","following_url":"https://api.github.com/users/mvo5/following{/other_user}","gists_url":"https://api.github.com/users/mvo5/gists{/gist_id}","starred_url":"https://api.github.com/users/mvo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvo5/subscriptions","organizations_url":"https://api.github.com/users/mvo5/orgs","repos_url":"https://api.github.com/users/mvo5/repos","events_url":"https://api.github.com/users/mvo5/events{/privacy}","received_events_url":"https://api.github.com/users/mvo5/received_events","type":"User","site_admin":false},"body":"Would it make sense to define these structs on the server (code) side or is that a stupid idea?","created_at":"2015-11-24T08:29:47Z","updated_at":"2015-11-24T08:29:47Z","html_url":"https://github.com/ubuntu-core/snappy/pull/154#discussion_r45707224","pull_request_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154","_links":{"self":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments/45707224"},"html":{"href":"https://github.com/ubuntu-core/snappy/pull/154#discussion_r45707224"},"pull_request":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154"}}},"pull_request":{"url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154","id":51564549,"html_url":"https://github.com/ubuntu-core/snappy/pull/154","diff_url":"https://github.com/ubuntu-core/snappy/pull/154.diff","patch_url":"https://github.com/ubuntu-core/snappy/pull/154.patch","issue_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/154","number":154,"state":"open","locked":false,"title":"minimal implementation of REST API client","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars.githubusercontent.com/u/1543430?v=3","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-23T18:58:36Z","updated_at":"2015-11-24T08:29:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49fe8ef4add9711b55a253f6d9020fe81c1375ed","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154/commits","review_comments_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154/comments","review_comment_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/154/comments","statuses_url":"https://api.github.com/repos/ubuntu-core/snappy/statuses/0c7fccb633bfa599837f050c636c2f141ae29d79","head":{"label":"chipaca:rest-client-cli","ref":"rest-client-cli","sha":"0c7fccb633bfa599837f050c636c2f141ae29d79","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars.githubusercontent.com/u/1543430?v=3","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"repo":{"id":45061368,"name":"snappy","full_name":"chipaca/snappy","owner":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars.githubusercontent.com/u/1543430?v=3","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chipaca/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/chipaca/snappy","forks_url":"https://api.github.com/repos/chipaca/snappy/forks","keys_url":"https://api.github.com/repos/chipaca/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chipaca/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chipaca/snappy/teams","hooks_url":"https://api.github.com/repos/chipaca/snappy/hooks","issue_events_url":"https://api.github.com/repos/chipaca/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/chipaca/snappy/events","assignees_url":"https://api.github.com/repos/chipaca/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/chipaca/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/chipaca/snappy/tags","blobs_url":"https://api.github.com/repos/chipaca/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chipaca/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chipaca/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/chipaca/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chipaca/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/chipaca/snappy/languages","stargazers_url":"https://api.github.com/repos/chipaca/snappy/stargazers","contributors_url":"https://api.github.com/repos/chipaca/snappy/contributors","subscribers_url":"https://api.github.com/repos/chipaca/snappy/subscribers","subscription_url":"https://api.github.com/repos/chipaca/snappy/subscription","commits_url":"https://api.github.com/repos/chipaca/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/chipaca/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/chipaca/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/chipaca/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/chipaca/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/chipaca/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chipaca/snappy/merges","archive_url":"https://api.github.com/repos/chipaca/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chipaca/snappy/downloads","issues_url":"https://api.github.com/repos/chipaca/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/chipaca/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/chipaca/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/chipaca/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chipaca/snappy/labels{/name}","releases_url":"https://api.github.com/repos/chipaca/snappy/releases{/id}","created_at":"2015-10-27T18:26:51Z","updated_at":"2015-10-27T18:26:55Z","pushed_at":"2015-11-23T22:23:30Z","git_url":"git://github.com/chipaca/snappy.git","ssh_url":"git@github.com:chipaca/snappy.git","clone_url":"https://github.com/chipaca/snappy.git","svn_url":"https://github.com/chipaca/snappy","homepage":null,"size":23313,"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":"ubuntu-core:master","ref":"master","sha":"57460a6ffdef7ad78a7c1ee2284c8b01ab95ad6a","user":{"login":"ubuntu-core","id":15022473,"avatar_url":"https://avatars.githubusercontent.com/u/15022473?v=3","gravatar_id":"","url":"https://api.github.com/users/ubuntu-core","html_url":"https://github.com/ubuntu-core","followers_url":"https://api.github.com/users/ubuntu-core/followers","following_url":"https://api.github.com/users/ubuntu-core/following{/other_user}","gists_url":"https://api.github.com/users/ubuntu-core/gists{/gist_id}","starred_url":"https://api.github.com/users/ubuntu-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubuntu-core/subscriptions","organizations_url":"https://api.github.com/users/ubuntu-core/orgs","repos_url":"https://api.github.com/users/ubuntu-core/repos","events_url":"https://api.github.com/users/ubuntu-core/events{/privacy}","received_events_url":"https://api.github.com/users/ubuntu-core/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snappy","full_name":"ubuntu-core/snappy","owner":{"login":"ubuntu-core","id":15022473,"avatar_url":"https://avatars.githubusercontent.com/u/15022473?v=3","gravatar_id":"","url":"https://api.github.com/users/ubuntu-core","html_url":"https://github.com/ubuntu-core","followers_url":"https://api.github.com/users/ubuntu-core/followers","following_url":"https://api.github.com/users/ubuntu-core/following{/other_user}","gists_url":"https://api.github.com/users/ubuntu-core/gists{/gist_id}","starred_url":"https://api.github.com/users/ubuntu-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubuntu-core/subscriptions","organizations_url":"https://api.github.com/users/ubuntu-core/orgs","repos_url":"https://api.github.com/users/ubuntu-core/repos","events_url":"https://api.github.com/users/ubuntu-core/events{/privacy}","received_events_url":"https://api.github.com/users/ubuntu-core/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubuntu-core/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":false,"url":"https://api.github.com/repos/ubuntu-core/snappy","forks_url":"https://api.github.com/repos/ubuntu-core/snappy/forks","keys_url":"https://api.github.com/repos/ubuntu-core/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubuntu-core/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubuntu-core/snappy/teams","hooks_url":"https://api.github.com/repos/ubuntu-core/snappy/hooks","issue_events_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/ubuntu-core/snappy/events","assignees_url":"https://api.github.com/repos/ubuntu-core/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/ubuntu-core/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/ubuntu-core/snappy/tags","blobs_url":"https://api.github.com/repos/ubuntu-core/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubuntu-core/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubuntu-core/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubuntu-core/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubuntu-core/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/ubuntu-core/snappy/languages","stargazers_url":"https://api.github.com/repos/ubuntu-core/snappy/stargazers","contributors_url":"https://api.github.com/repos/ubuntu-core/snappy/contributors","subscribers_url":"https://api.github.com/repos/ubuntu-core/snappy/subscribers","subscription_url":"https://api.github.com/repos/ubuntu-core/snappy/subscription","commits_url":"https://api.github.com/repos/ubuntu-core/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubuntu-core/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubuntu-core/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubuntu-core/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/ubuntu-core/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubuntu-core/snappy/merges","archive_url":"https://api.github.com/repos/ubuntu-core/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubuntu-core/snappy/downloads","issues_url":"https://api.github.com/repos/ubuntu-core/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/ubuntu-core/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/ubuntu-core/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubuntu-core/snappy/labels{/name}","releases_url":"https://api.github.com/repos/ubuntu-core/snappy/releases{/id}","created_at":"2015-10-21T11:51:46Z","updated_at":"2015-11-23T09:02:22Z","pushed_at":"2015-11-24T08:15:12Z","git_url":"git://github.com/ubuntu-core/snappy.git","ssh_url":"git@github.com:ubuntu-core/snappy.git","clone_url":"https://github.com/ubuntu-core/snappy.git","svn_url":"https://github.com/ubuntu-core/snappy","homepage":null,"size":23902,"stargazers_count":35,"watchers_count":35,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":16,"forks":16,"open_issues":16,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154"},"html":{"href":"https://github.com/ubuntu-core/snappy/pull/154"},"issue":{"href":"https://api.github.com/repos/ubuntu-core/snappy/issues/154"},"comments":{"href":"https://api.github.com/repos/ubuntu-core/snappy/issues/154/comments"},"review_comments":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154/comments"},"review_comment":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/154/commits"},"statuses":{"href":"https://api.github.com/repos/ubuntu-core/snappy/statuses/0c7fccb633bfa599837f050c636c2f141ae29d79"}}}}