{"action":"created","comment":{"url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/comments/45134290","id":45134290,"diff_hunk":"@@ -0,0 +1,150 @@\n++++\n+author = [\"Matt Farina\"]\n+date = \"2015-12-02T08:00:00+00:00\"\n+title = \"Working with Semantic Versions\"\n+series = [\"Advent 2015\"]\n+draft = true\n++++\n+\n+[Semantic Versioning](http://semver.org/) (a.k.a SemVer) has become a popular way\n+to handle versions. The structure not only allows for incremental releases but\n+allows people and automation to deduce what those changes mean. This makes SemVer\n+ideal for a wide range of uses even though they are most well known for package\n+managers.\n+\n+Before we look at how we can work with them in Go let's take a look at what a\n+semantic version looks like.\n+\n+![Semantic Version](/postimages/advent-2015/semver.png)\n+\n+\n+The diagram shows all the parts of the parts of a semantic version. Quite often\n+you'll see just the first 3 numbers separate by a `.`. A general breakdown of a\n+semantic version is:\n+\n+- The major number is incremented when the API to the package or application\n+  changes in backwards incompatible ways.\n+- The minor number is incremented when new features are added to the API without\n+  breaking backwards compatibility. If the major number is incremented the\n+  minor number returns to 0.\n+- The patch number is incremented when no new features are added but bug fixes\n+  are released. If the major or minor numbers are incremented this returns to 0.\n+- A pre-release is a `.` separated list of identifiers following a `-`. For\n+  example, `1.2.3-beta.1`. These are optional and are only needed for pre-release\n+  versions. In this case `1.2.3` would be a release version and newer.\n+- The final section of information is build metadata. This is a `.` separated\n+  list of identifiers following a `+`. This is different from pre-release\n+  information and should be ignored when determining precedence.\n+\n+While the spec doesn't list anything about a `v` prefix on a semantic version\n+they are sometimes present. For example, you might see a semantic version as\n+`v1.2.3`. In this case the `v` should be ignored.\n+\n+This and more can be found in the [semantic version spec](http://semver.org).\n+\n+Because of the nature of semantic versions it's possible to easily parse them,\n+sort them, and compare a version against a range or constraint.\n+\n+## Parsing Semantic Versions\n+\n+There are a number of packages designed to work with semantic versions. In this\n+case we're going to use the\n+[`github.com/Masterminds/semver`](https://github.com/Masterminds/semver) package.\n+It's built to the spec, supports the optional `v` prefix, provides sorting, and\n+has the ability to test if a semantic version is within a range or other\n+constraint. The constraint handling is similar or the same as you'll find in\n+other languages including Node.js, Rust, and others.\n+\n+The following example parses a semantic version and displays an error if it could\n+not be parsed or prints out the major version if there were no issues.\n+```go\n+v, err := semver.NewVersion(\"1.2.3-beta.1+build345\")\n+if err != nil {\n+    fmt.Println(err)\n+} else {\n+    fmt.Println(v.Major())\n+}\n+```\n+The returned object is an instance of [`semver.Version`](https://godoc.org/github.com/Masterminds/semver#Version)\n+containing a number of useful methods. If the version wasn't semantic it will\n+return a\n+[`semver.ErrInvalidSemVer`](https://godoc.org/github.com/Masterminds/semver#pkg-variables)\n+error.\n+\n+The real power isn't in the ability to parse an individual semantic version but\n+to perform more complicated operations on them.\n+\n+## Sorting Semantic Versions\n+\n+When you have a series of versions they may not be in any order. Wouldn't it be\n+great to sort semantic versions using the `sort` package in the standard library?\n+With [`github.com/Masterminds/semver`](https://github.com/Masterminds/semver)\n+you can do just that. For example,\n+\n+```go\n+raw := []string{\"1.2.3\", \"1.0\", \"1.0.0-alpha.1\" \"1.3\", \"2\", \"0.4.2\",}\n+vs := make([]*semver.Version, len(raw))\n+for i, r := range raw {\n+    v, err := semver.NewVersion(r)\n+    if err != nil {\n+        t.Errorf(\"Error parsing version: %s\", err)\n+    }\n+\n+    vs[i] = v\n+}\n+\n+sort.Sort(semver.Collection(vs))\n+```\n+\n+In this example a series of semantic versions are converted into instances of\n+[`semver.Version`](https://godoc.org/github.com/Masterminds/semver#Version) and\n+turned into a [`semver.Collection`](https://godoc.org/github.com/Masterminds/semver#Collection).\n+A [`semver.Collection`](https://godoc.org/github.com/Masterminds/semver#Collection)\n+has the functions needed by the `sort` package to reorder the collection. This","path":"content/advent-2015/semver.md","position":103,"original_position":103,"commit_id":"b375565da4e805a26924a3ab4b44e578d747b036","original_commit_id":"b375565da4e805a26924a3ab4b44e578d747b036","user":{"login":"nathany","id":4566,"avatar_url":"https://avatars.githubusercontent.com/u/4566?v=3","gravatar_id":"","url":"https://api.github.com/users/nathany","html_url":"https://github.com/nathany","followers_url":"https://api.github.com/users/nathany/followers","following_url":"https://api.github.com/users/nathany/following{/other_user}","gists_url":"https://api.github.com/users/nathany/gists{/gist_id}","starred_url":"https://api.github.com/users/nathany/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathany/subscriptions","organizations_url":"https://api.github.com/users/nathany/orgs","repos_url":"https://api.github.com/users/nathany/repos","events_url":"https://api.github.com/users/nathany/events{/privacy}","received_events_url":"https://api.github.com/users/nathany/received_events","type":"User","site_admin":false},"body":"~~functions~~ <ins>methods</ins> needed","created_at":"2015-11-17T22:46:04Z","updated_at":"2015-11-17T22:46:04Z","html_url":"https://github.com/gopheracademy/gopheracademy-web/pull/139#discussion_r45134290","pull_request_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139","_links":{"self":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/comments/45134290"},"html":{"href":"https://github.com/gopheracademy/gopheracademy-web/pull/139#discussion_r45134290"},"pull_request":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139"}}},"pull_request":{"url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139","id":50426086,"html_url":"https://github.com/gopheracademy/gopheracademy-web/pull/139","diff_url":"https://github.com/gopheracademy/gopheracademy-web/pull/139.diff","patch_url":"https://github.com/gopheracademy/gopheracademy-web/pull/139.patch","issue_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues/139","number":139,"state":"open","locked":false,"title":"Adding advent 2015 post on semver","user":{"login":"mattfarina","id":62991,"avatar_url":"https://avatars.githubusercontent.com/u/62991?v=3","gravatar_id":"","url":"https://api.github.com/users/mattfarina","html_url":"https://github.com/mattfarina","followers_url":"https://api.github.com/users/mattfarina/followers","following_url":"https://api.github.com/users/mattfarina/following{/other_user}","gists_url":"https://api.github.com/users/mattfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/mattfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattfarina/subscriptions","organizations_url":"https://api.github.com/users/mattfarina/orgs","repos_url":"https://api.github.com/users/mattfarina/repos","events_url":"https://api.github.com/users/mattfarina/events{/privacy}","received_events_url":"https://api.github.com/users/mattfarina/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-11T19:37:56Z","updated_at":"2015-11-17T22:46:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2d30fcdd2e9ffcfefdbd17270b7b2a74fcc1ef1d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139/commits","review_comments_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139/comments","review_comment_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues/139/comments","statuses_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/statuses/b375565da4e805a26924a3ab4b44e578d747b036","head":{"label":"mattfarina:advent-2015/semver","ref":"advent-2015/semver","sha":"b375565da4e805a26924a3ab4b44e578d747b036","user":{"login":"mattfarina","id":62991,"avatar_url":"https://avatars.githubusercontent.com/u/62991?v=3","gravatar_id":"","url":"https://api.github.com/users/mattfarina","html_url":"https://github.com/mattfarina","followers_url":"https://api.github.com/users/mattfarina/followers","following_url":"https://api.github.com/users/mattfarina/following{/other_user}","gists_url":"https://api.github.com/users/mattfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/mattfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattfarina/subscriptions","organizations_url":"https://api.github.com/users/mattfarina/orgs","repos_url":"https://api.github.com/users/mattfarina/repos","events_url":"https://api.github.com/users/mattfarina/events{/privacy}","received_events_url":"https://api.github.com/users/mattfarina/received_events","type":"User","site_admin":false},"repo":{"id":45546102,"name":"gopheracademy-web","full_name":"mattfarina/gopheracademy-web","owner":{"login":"mattfarina","id":62991,"avatar_url":"https://avatars.githubusercontent.com/u/62991?v=3","gravatar_id":"","url":"https://api.github.com/users/mattfarina","html_url":"https://github.com/mattfarina","followers_url":"https://api.github.com/users/mattfarina/followers","following_url":"https://api.github.com/users/mattfarina/following{/other_user}","gists_url":"https://api.github.com/users/mattfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/mattfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattfarina/subscriptions","organizations_url":"https://api.github.com/users/mattfarina/orgs","repos_url":"https://api.github.com/users/mattfarina/repos","events_url":"https://api.github.com/users/mattfarina/events{/privacy}","received_events_url":"https://api.github.com/users/mattfarina/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mattfarina/gopheracademy-web","description":"Public Website for blog.GopherAcademy.com","fork":true,"url":"https://api.github.com/repos/mattfarina/gopheracademy-web","forks_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/forks","keys_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/teams","hooks_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/hooks","issue_events_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/issues/events{/number}","events_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/events","assignees_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/assignees{/user}","branches_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/branches{/branch}","tags_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/tags","blobs_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/statuses/{sha}","languages_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/languages","stargazers_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/stargazers","contributors_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/contributors","subscribers_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/subscribers","subscription_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/subscription","commits_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/contents/{+path}","compare_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/merges","archive_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/downloads","issues_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/issues{/number}","pulls_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/pulls{/number}","milestones_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/milestones{/number}","notifications_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/labels{/name}","releases_url":"https://api.github.com/repos/mattfarina/gopheracademy-web/releases{/id}","created_at":"2015-11-04T14:58:47Z","updated_at":"2015-11-04T14:58:48Z","pushed_at":"2015-11-17T20:40:18Z","git_url":"git://github.com/mattfarina/gopheracademy-web.git","ssh_url":"git@github.com:mattfarina/gopheracademy-web.git","clone_url":"https://github.com/mattfarina/gopheracademy-web.git","svn_url":"https://github.com/mattfarina/gopheracademy-web","homepage":"http://blog.gopheracademy.com","size":11265,"stargazers_count":0,"watchers_count":0,"language":"CSS","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":"gopheracademy:master","ref":"master","sha":"98b49329a0a460cae92eafc79e9396c359d71ff8","user":{"login":"gopheracademy","id":7428627,"avatar_url":"https://avatars.githubusercontent.com/u/7428627?v=3","gravatar_id":"","url":"https://api.github.com/users/gopheracademy","html_url":"https://github.com/gopheracademy","followers_url":"https://api.github.com/users/gopheracademy/followers","following_url":"https://api.github.com/users/gopheracademy/following{/other_user}","gists_url":"https://api.github.com/users/gopheracademy/gists{/gist_id}","starred_url":"https://api.github.com/users/gopheracademy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopheracademy/subscriptions","organizations_url":"https://api.github.com/users/gopheracademy/orgs","repos_url":"https://api.github.com/users/gopheracademy/repos","events_url":"https://api.github.com/users/gopheracademy/events{/privacy}","received_events_url":"https://api.github.com/users/gopheracademy/received_events","type":"Organization","site_admin":false},"repo":{"id":23665322,"name":"gopheracademy-web","full_name":"gopheracademy/gopheracademy-web","owner":{"login":"gopheracademy","id":7428627,"avatar_url":"https://avatars.githubusercontent.com/u/7428627?v=3","gravatar_id":"","url":"https://api.github.com/users/gopheracademy","html_url":"https://github.com/gopheracademy","followers_url":"https://api.github.com/users/gopheracademy/followers","following_url":"https://api.github.com/users/gopheracademy/following{/other_user}","gists_url":"https://api.github.com/users/gopheracademy/gists{/gist_id}","starred_url":"https://api.github.com/users/gopheracademy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopheracademy/subscriptions","organizations_url":"https://api.github.com/users/gopheracademy/orgs","repos_url":"https://api.github.com/users/gopheracademy/repos","events_url":"https://api.github.com/users/gopheracademy/events{/privacy}","received_events_url":"https://api.github.com/users/gopheracademy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gopheracademy/gopheracademy-web","description":"Public Website for blog.GopherAcademy.com","fork":false,"url":"https://api.github.com/repos/gopheracademy/gopheracademy-web","forks_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/forks","keys_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/teams","hooks_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/hooks","issue_events_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues/events{/number}","events_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/events","assignees_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/assignees{/user}","branches_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/branches{/branch}","tags_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/tags","blobs_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/statuses/{sha}","languages_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/languages","stargazers_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/stargazers","contributors_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/contributors","subscribers_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/subscribers","subscription_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/subscription","commits_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/contents/{+path}","compare_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/merges","archive_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/downloads","issues_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues{/number}","pulls_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls{/number}","milestones_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/milestones{/number}","notifications_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/labels{/name}","releases_url":"https://api.github.com/repos/gopheracademy/gopheracademy-web/releases{/id}","created_at":"2014-09-04T14:18:26Z","updated_at":"2015-11-05T03:44:57Z","pushed_at":"2015-11-17T20:40:18Z","git_url":"git://github.com/gopheracademy/gopheracademy-web.git","ssh_url":"git@github.com:gopheracademy/gopheracademy-web.git","clone_url":"https://github.com/gopheracademy/gopheracademy-web.git","svn_url":"https://github.com/gopheracademy/gopheracademy-web","homepage":"http://blog.gopheracademy.com","size":11279,"stargazers_count":62,"watchers_count":62,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":3,"forks":57,"open_issues":3,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139"},"html":{"href":"https://github.com/gopheracademy/gopheracademy-web/pull/139"},"issue":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues/139"},"comments":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/issues/139/comments"},"review_comments":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139/comments"},"review_comment":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/pulls/139/commits"},"statuses":{"href":"https://api.github.com/repos/gopheracademy/gopheracademy-web/statuses/b375565da4e805a26924a3ab4b44e578d747b036"}}}}