{"action":"created","issue":{"url":"https://api.github.com/repos/appc/spec/issues/541","labels_url":"https://api.github.com/repos/appc/spec/issues/541/labels{/name}","comments_url":"https://api.github.com/repos/appc/spec/issues/541/comments","events_url":"https://api.github.com/repos/appc/spec/issues/541/events","html_url":"https://github.com/appc/spec/pull/541","id":118955519,"number":541,"title":"schema/types: rework empty volume type code","user":{"login":"jonboulle","id":2601015,"avatar_url":"https://avatars.githubusercontent.com/u/2601015?v=3","gravatar_id":"","url":"https://api.github.com/users/jonboulle","html_url":"https://github.com/jonboulle","followers_url":"https://api.github.com/users/jonboulle/followers","following_url":"https://api.github.com/users/jonboulle/following{/other_user}","gists_url":"https://api.github.com/users/jonboulle/gists{/gist_id}","starred_url":"https://api.github.com/users/jonboulle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonboulle/subscriptions","organizations_url":"https://api.github.com/users/jonboulle/orgs","repos_url":"https://api.github.com/users/jonboulle/repos","events_url":"https://api.github.com/users/jonboulle/events{/privacy}","received_events_url":"https://api.github.com/users/jonboulle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-26T01:49:41Z","updated_at":"2015-11-26T01:50:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/appc/spec/pulls/541","html_url":"https://github.com/appc/spec/pull/541","diff_url":"https://github.com/appc/spec/pull/541.diff","patch_url":"https://github.com/appc/spec/pull/541.patch"},"body":"tl;dr: this patch:\n- fixes a panic in the Volume type's String() method\n- ensures that the serialization of a Volume to/from a string is\n  reversible - i.e., `s == VolumeFromString(s).String()`\n\nFull details:\n\nThe `Volume` type is polymorphic; it can be of several different Kinds,\nand for each Kind only a select few fields are valid. When new fields\n(`mode`, `uid`, `gid`) were added to the `empty` volume Kind (via\n26af7cefe402259b348fdfa2299d8d2e0a595e2e), they were simply added as new\nfields. However, this means that Volume structs of Kinds for which those\nfields are not valid (e.g. the `host` Kind) would necessarily have\nvalues set in those fields - since in Go any fields will be\nautomatically set to their zero value. To mitigate this, the previous\ncode set special sentinel values to those fields (e.g. -1 to the\n`uid`/`mode` fields) to indicate that they were \"unset\"; but this is\nslightly awkward since it necessitates manually setting those sentinel\nvalues at certain points.\n\nThis patch instead change those fields to be pointers, so that it is\ntrivially possible to determine whether or not those fields are really\nset, and disambiguate from the zeroed value case. This also means that a\n\"zeroed\" Volume type is really unset and does not need modification to\nset the sentinels appropriately.\n\nAnother change is in how exactly a Volume type is serialized to a\nstring. `String()` previously attempted to dereference the `readOnly`\nfield even if it was not necessarily set. Even though such a nil\ndereference would ordinarily cause the Go runtime to panic, the\n`fmt.Printf` function (and friends) uses a `recover()` to actually\n_catch_ any panic occurred, so instead this results in a weird panic\ntrace _within the returned string_, but business otherwise continues as\nusual (smdh).\n\nAs well as fixing this panic (by checking the pointer before\ndereferencing), we now also construct the serialized Volume string\npiece-by-piece, only if fields are set; for example, if an `empty`\nVolume's `mode` field is set to the default value, we will omit it from\nthe serialized string."},"comment":{"url":"https://api.github.com/repos/appc/spec/issues/comments/159778024","html_url":"https://github.com/appc/spec/pull/541#issuecomment-159778024","issue_url":"https://api.github.com/repos/appc/spec/issues/541","id":159778024,"user":{"login":"jonboulle","id":2601015,"avatar_url":"https://avatars.githubusercontent.com/u/2601015?v=3","gravatar_id":"","url":"https://api.github.com/users/jonboulle","html_url":"https://github.com/jonboulle","followers_url":"https://api.github.com/users/jonboulle/followers","following_url":"https://api.github.com/users/jonboulle/following{/other_user}","gists_url":"https://api.github.com/users/jonboulle/gists{/gist_id}","starred_url":"https://api.github.com/users/jonboulle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonboulle/subscriptions","organizations_url":"https://api.github.com/users/jonboulle/orgs","repos_url":"https://api.github.com/users/jonboulle/repos","events_url":"https://api.github.com/users/jonboulle/events{/privacy}","received_events_url":"https://api.github.com/users/jonboulle/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T01:50:35Z","updated_at":"2015-11-26T01:50:35Z","body":"/cc @iaguis "}}