{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubectl/pulls/comments/175602181","pull_request_review_id":105099663,"id":175602181,"diff_hunk":"@@ -0,0 +1,77 @@\n+/*\n+Copyright 2018 The Kubernetes Authors.\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+*/\n+\n+package unstruct_test\n+\n+import (\n+\t\"fmt\"\n+\n+\t\"k8s.io/kubectl/pkg/framework/unstruct\"\n+\n+\t\"gopkg.in/yaml.v2\"\n+)\n+\n+func Example() {\n+\tu := unstruct.New(map[string]interface{}{\n+\t\t\"int\": 1,\n+\t\t\"list\": []interface{}{\n+\t\t\t\"A string.\",\n+\t\t\t2,\n+\t\t},\n+\t})\n+\n+\tu.Map().Field(\"int\").Set(\"Number one\")\n+\tu.Map().Field(\"string\").Set(\"my string\")\n+\ts := u.Map().Field(\"list\").Slice()\n+\ts.Append(\"Another string.\")\n+\ts.Append([]interface{}{})\n+\ts.At(3).Slice().Append(4)\n+\n+\ty, _ := yaml.Marshal(u.Data())\n+\tfmt.Println(string(y))\n+\t// Output: int: Number one\n+\t// list:\n+\t// - A string.\n+\t// - 2\n+\t// - Another string.\n+\t// - - 4\n+\t// string: my string\n+}\n+\n+// This example demonstrates how the interface lets you chain calls\n+// to easily set and change values in a unstruct type.\n+func Example_chaining() {\n+\tu := unstruct.New(nil)\n+\n+\tu.Map().\n+\t\tField(\"int\").Set(\"Number one\").Parent().Map().\n+\t\tField(\"string\").Set(\"my string\").Parent().Map().\n+\t\tField(\"list\").Slice().\n+\t\tAppend(\"A string.\").Parent().Slice().\n+\t\tAppend(2).Parent().Slice().\n+\t\tAppend(\"Another string.\").Parent().Slice().\n+\t\tAppend(nil).Slice().Append(4)\n+\n+\ty, _ := yaml.Marshal(u.Data())\n+\tfmt.Println(string(y))","path":"pkg/framework/unstruct/example_test.go","position":69,"original_position":69,"commit_id":"811793aa54ae30bbc77555d1037896580119fbce","original_commit_id":"3f0844c3145d53eaa566f4676cebf3d2fa9327ff","user":{"login":"monopole","id":2928188,"avatar_url":"https://avatars3.githubusercontent.com/u/2928188?v=4","gravatar_id":"","url":"https://api.github.com/users/monopole","html_url":"https://github.com/monopole","followers_url":"https://api.github.com/users/monopole/followers","following_url":"https://api.github.com/users/monopole/following{/other_user}","gists_url":"https://api.github.com/users/monopole/gists{/gist_id}","starred_url":"https://api.github.com/users/monopole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monopole/subscriptions","organizations_url":"https://api.github.com/users/monopole/orgs","repos_url":"https://api.github.com/users/monopole/repos","events_url":"https://api.github.com/users/monopole/events{/privacy}","received_events_url":"https://api.github.com/users/monopole/received_events","type":"User","site_admin":false},"body":"Please add an error example.\r\n","created_at":"2018-03-19T22:10:04Z","updated_at":"2018-03-19T22:39:31Z","html_url":"https://github.com/kubernetes/kubectl/pull/258#discussion_r175602181","pull_request_url":"https://api.github.com/repos/kubernetes/kubectl/pulls/258","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubectl/pulls/comments/175602181"},"html":{"href":"https://github.com/kubernetes/kubectl/pull/258#discussion_r175602181"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubectl/pulls/258"}},"in_reply_to_id":167072043},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubectl/pulls/258","id":167512793,"html_url":"https://github.com/kubernetes/kubectl/pull/258","diff_url":"https://github.com/kubernetes/kubectl/pull/258.diff","patch_url":"https://github.com/kubernetes/kubectl/pull/258.patch","issue_url":"https://api.github.com/repos/kubernetes/kubectl/issues/258","number":258,"state":"open","locked":false,"title":"Unstruct package framework for json/yaml manipulation","user":{"login":"apelisse","id":1929644,"avatar_url":"https://avatars0.githubusercontent.com/u/1929644?v=4","gravatar_id":"","url":"https://api.github.com/users/apelisse","html_url":"https://github.com/apelisse","followers_url":"https://api.github.com/users/apelisse/followers","following_url":"https://api.github.com/users/apelisse/following{/other_user}","gists_url":"https://api.github.com/users/apelisse/gists{/gist_id}","starred_url":"https://api.github.com/users/apelisse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apelisse/subscriptions","organizations_url":"https://api.github.com/users/apelisse/orgs","repos_url":"https://api.github.com/users/apelisse/repos","events_url":"https://api.github.com/users/apelisse/events{/privacy}","received_events_url":"https://api.github.com/users/apelisse/received_events","type":"User","site_admin":false},"body":"The package \"unstruct\" provides utility functions to walk through and modify an unstructured json/yaml object (as decoded in an `interface{}`)\r\n","created_at":"2018-02-06T19:50:24Z","updated_at":"2018-03-19T22:39:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4240c8d7e8b23bbad88732e16aa8a1789799b599","assignee":null,"assignees":[],"requested_reviewers":[{"login":"mengqiy","id":2589105,"avatar_url":"https://avatars1.githubusercontent.com/u/2589105?v=4","gravatar_id":"","url":"https://api.github.com/users/mengqiy","html_url":"https://github.com/mengqiy","followers_url":"https://api.github.com/users/mengqiy/followers","following_url":"https://api.github.com/users/mengqiy/following{/other_user}","gists_url":"https://api.github.com/users/mengqiy/gists{/gist_id}","starred_url":"https://api.github.com/users/mengqiy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mengqiy/subscriptions","organizations_url":"https://api.github.com/users/mengqiy/orgs","repos_url":"https://api.github.com/users/mengqiy/repos","events_url":"https://api.github.com/users/mengqiy/events{/privacy}","received_events_url":"https://api.github.com/users/mengqiy/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":573132968,"url":"https://api.github.com/repos/kubernetes/kubectl/labels/cncf-cla:%20yes","name":"cncf-cla: yes","color":"bfe5bf","default":false},{"id":631708868,"url":"https://api.github.com/repos/kubernetes/kubectl/labels/size/XXL","name":"size/XXL","color":"ee0000","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubectl/pulls/258/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubectl/pulls/258/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubectl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubectl/issues/258/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubectl/statuses/811793aa54ae30bbc77555d1037896580119fbce","head":{"label":"apelisse:unstruct","ref":"unstruct","sha":"811793aa54ae30bbc77555d1037896580119fbce","user":{"login":"apelisse","id":1929644,"avatar_url":"https://avatars0.githubusercontent.com/u/1929644?v=4","gravatar_id":"","url":"https://api.github.com/users/apelisse","html_url":"https://github.com/apelisse","followers_url":"https://api.github.com/users/apelisse/followers","following_url":"https://api.github.com/users/apelisse/following{/other_user}","gists_url":"https://api.github.com/users/apelisse/gists{/gist_id}","starred_url":"https://api.github.com/users/apelisse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apelisse/subscriptions","organizations_url":"https://api.github.com/users/apelisse/orgs","repos_url":"https://api.github.com/users/apelisse/repos","events_url":"https://api.github.com/users/apelisse/events{/privacy}","received_events_url":"https://api.github.com/users/apelisse/received_events","type":"User","site_admin":false},"repo":{"id":110606432,"name":"kubectl","full_name":"apelisse/kubectl","owner":{"login":"apelisse","id":1929644,"avatar_url":"https://avatars0.githubusercontent.com/u/1929644?v=4","gravatar_id":"","url":"https://api.github.com/users/apelisse","html_url":"https://github.com/apelisse","followers_url":"https://api.github.com/users/apelisse/followers","following_url":"https://api.github.com/users/apelisse/following{/other_user}","gists_url":"https://api.github.com/users/apelisse/gists{/gist_id}","starred_url":"https://api.github.com/users/apelisse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apelisse/subscriptions","organizations_url":"https://api.github.com/users/apelisse/orgs","repos_url":"https://api.github.com/users/apelisse/repos","events_url":"https://api.github.com/users/apelisse/events{/privacy}","received_events_url":"https://api.github.com/users/apelisse/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/apelisse/kubectl","description":"Issue tracker and mirror of kubectl code","fork":true,"url":"https://api.github.com/repos/apelisse/kubectl","forks_url":"https://api.github.com/repos/apelisse/kubectl/forks","keys_url":"https://api.github.com/repos/apelisse/kubectl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apelisse/kubectl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apelisse/kubectl/teams","hooks_url":"https://api.github.com/repos/apelisse/kubectl/hooks","issue_events_url":"https://api.github.com/repos/apelisse/kubectl/issues/events{/number}","events_url":"https://api.github.com/repos/apelisse/kubectl/events","assignees_url":"https://api.github.com/repos/apelisse/kubectl/assignees{/user}","branches_url":"https://api.github.com/repos/apelisse/kubectl/branches{/branch}","tags_url":"https://api.github.com/repos/apelisse/kubectl/tags","blobs_url":"https://api.github.com/repos/apelisse/kubectl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apelisse/kubectl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apelisse/kubectl/git/refs{/sha}","trees_url":"https://api.github.com/repos/apelisse/kubectl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apelisse/kubectl/statuses/{sha}","languages_url":"https://api.github.com/repos/apelisse/kubectl/languages","stargazers_url":"https://api.github.com/repos/apelisse/kubectl/stargazers","contributors_url":"https://api.github.com/repos/apelisse/kubectl/contributors","subscribers_url":"https://api.github.com/repos/apelisse/kubectl/subscribers","subscription_url":"https://api.github.com/repos/apelisse/kubectl/subscription","commits_url":"https://api.github.com/repos/apelisse/kubectl/commits{/sha}","git_commits_url":"https://api.github.com/repos/apelisse/kubectl/git/commits{/sha}","comments_url":"https://api.github.com/repos/apelisse/kubectl/comments{/number}","issue_comment_url":"https://api.github.com/repos/apelisse/kubectl/issues/comments{/number}","contents_url":"https://api.github.com/repos/apelisse/kubectl/contents/{+path}","compare_url":"https://api.github.com/repos/apelisse/kubectl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apelisse/kubectl/merges","archive_url":"https://api.github.com/repos/apelisse/kubectl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apelisse/kubectl/downloads","issues_url":"https://api.github.com/repos/apelisse/kubectl/issues{/number}","pulls_url":"https://api.github.com/repos/apelisse/kubectl/pulls{/number}","milestones_url":"https://api.github.com/repos/apelisse/kubectl/milestones{/number}","notifications_url":"https://api.github.com/repos/apelisse/kubectl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apelisse/kubectl/labels{/name}","releases_url":"https://api.github.com/repos/apelisse/kubectl/releases{/id}","deployments_url":"https://api.github.com/repos/apelisse/kubectl/deployments","created_at":"2017-11-13T21:49:30Z","updated_at":"2017-11-13T21:49:32Z","pushed_at":"2018-03-19T17:41:32Z","git_url":"git://github.com/apelisse/kubectl.git","ssh_url":"git@github.com:apelisse/kubectl.git","clone_url":"https://github.com/apelisse/kubectl.git","svn_url":"https://github.com/apelisse/kubectl","homepage":null,"size":25547,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"50b974a5fe0c95b3328dac7f20981f41d74f6949","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars2.githubusercontent.com/u/13629408?v=4","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":86742497,"name":"kubectl","full_name":"kubernetes/kubectl","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars2.githubusercontent.com/u/13629408?v=4","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/kubectl","description":"Issue tracker and mirror of kubectl code","fork":false,"url":"https://api.github.com/repos/kubernetes/kubectl","forks_url":"https://api.github.com/repos/kubernetes/kubectl/forks","keys_url":"https://api.github.com/repos/kubernetes/kubectl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/kubectl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/kubectl/teams","hooks_url":"https://api.github.com/repos/kubernetes/kubectl/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/kubectl/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/kubectl/events","assignees_url":"https://api.github.com/repos/kubernetes/kubectl/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/kubectl/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/kubectl/tags","blobs_url":"https://api.github.com/repos/kubernetes/kubectl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/kubectl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/kubectl/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/kubectl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/kubectl/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/kubectl/languages","stargazers_url":"https://api.github.com/repos/kubernetes/kubectl/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/kubectl/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/kubectl/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/kubectl/subscription","commits_url":"https://api.github.com/repos/kubernetes/kubectl/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/kubectl/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/kubectl/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/kubectl/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/kubectl/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/kubectl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/kubectl/merges","archive_url":"https://api.github.com/repos/kubernetes/kubectl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/kubectl/downloads","issues_url":"https://api.github.com/repos/kubernetes/kubectl/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/kubectl/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/kubectl/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/kubectl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/kubectl/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/kubectl/releases{/id}","deployments_url":"https://api.github.com/repos/kubernetes/kubectl/deployments","created_at":"2017-03-30T19:50:22Z","updated_at":"2018-03-19T21:45:04Z","pushed_at":"2018-03-19T21:45:01Z","git_url":"git://github.com/kubernetes/kubectl.git","ssh_url":"git@github.com:kubernetes/kubectl.git","clone_url":"https://github.com/kubernetes/kubectl.git","svn_url":"https://github.com/kubernetes/kubectl","homepage":null,"size":25454,"stargazers_count":116,"watchers_count":116,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":65,"mirror_url":null,"archived":false,"open_issues_count":100,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":65,"open_issues":100,"watchers":116,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubectl/pulls/258"},"html":{"href":"https://github.com/kubernetes/kubectl/pull/258"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubectl/issues/258"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubectl/issues/258/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubectl/pulls/258/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubectl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubectl/pulls/258/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubectl/statuses/811793aa54ae30bbc77555d1037896580119fbce"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"monopole"}}