<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by freeformz on Medium]]></title>
        <description><![CDATA[Stories by freeformz on Medium]]></description>
        <link>https://medium.com/@freeformz?source=rss-f90e265567b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1uMOVGJJiWF-NHZzRLx31w.jpeg</url>
            <title>Stories by freeformz on Medium</title>
            <link>https://medium.com/@freeformz?source=rss-f90e265567b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:07:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@freeformz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Buttermilk Pancakes]]></title>
            <link>https://medium.com/@freeformz/buttermilk-pancakes-948c42d1e6b?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/948c42d1e6b</guid>
            <category><![CDATA[buttermilk]]></category>
            <category><![CDATA[pancakes]]></category>
            <category><![CDATA[recipe]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Tue, 20 Nov 2018 17:05:44 GMT</pubDate>
            <atom:updated>2018-11-21T16:11:50.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZ0ZGx8aJJZ0Nttrk65qGw@2x.jpeg" /></figure><h4>Dry Mix</h4><ul><li>6 cups all-purpose flour</li><li>1/2 tbsp (1.5 tsp) baking soda</li><li>1 tbsp (3 tsp) baking powder</li><li>1 tbsp (3 tsp) kosher salt</li><li>2 tbsp (6 tsp) sugar</li><li>1 tbsp (3 tsp) corn starch</li></ul><p>Combine all the ingredients in a lidded container, stir with a whisk and cover. Shake to mix further.</p><h4>Wet Mix (per cup of dry mix)</h4><ul><li>1 c Buttermilk</li><li>1 oz (2 tbsp) butter, melted</li><li>1 egg</li></ul><h4>Hardware</h4><ul><li>Large mixing bowl</li><li>Wet &amp; dry measuring cups</li><li>Ramekin for melting butter</li><li>Measuring spoons</li><li>Whisk, Ladle, &amp; Silicon Spatula</li><li>Electric griddle</li></ul><h4>Misc</h4><ul><li>Butter for the griddle</li></ul><h4>Directions</h4><p>Put eggs and buttermilk in a bowl and whisk together until incorporated. Add dry mix. Using a whisk, mix the wet and dry together while pouring the melted butter into the bowl. Mix until everything comes together. Be careful to not over mix. Lumps are good, they will cook out and they add structure in the meantime.</p><p>Preheat the griddle to 350°F. For each location on the griddle where you will place a pancake, swirl the stick of butter to melt a little bit of onto the griddle.</p><p>Ladle the batter (it should be thick) onto the griddle locations where you melted the butter. On our griddle, I can typically place 6 pancakes at a time, but the number will vary depending on how large you like your pancakes and the size of your griddle. For reference we typically get 9–10 pancakes from 2c dry mix + 2c buttermilk + 2 oz butter + 2 eggs.</p><p>This is the time to add any “mixins” to your pancakes, or just skip “mixins” for plain pancakes. Popular “mixins” in my house are:</p><ul><li>Frozen (or fresh) blueberries</li><li>Chocolate chips, M&amp;Ms, Reese’s Pieces, etc.</li><li>Peanut (or any nut) butter</li><li>Banana, Persimmon, Apple, Pear, Peach, etc pieces</li></ul><p>In 3–5 minutes, when the pancakes start to look “dry” around the edges and/or bubbles form and pop in the middle, the pancakes are ready to flip. They should be golden brown on the cooked side. Cook for 3–5 minutes on the other side, until golden brown on the bottom. Do not press down on these pancakes while cooking.</p><p>You can hold cooked pancakes in a toaster oven or normal oven set to ~160–180°F until the rest are done.</p><p>Serve with real maple syrup and soft, room temp. butter or whipped cream.</p><h4>Previous butter incorporation methods</h4><p>1. Grate near frozen butter and cut into dry mix like you would for biscuits/pie dough.</p><p>This ended up being a bunch of extra work with no noticeable difference. I also had to have frozen or really cold butter at hand.</p><p>2. Mix Egg whites with buttermilk and egg yolks with melted butter. Then combine those two mixtures. Then add dry mix.</p><p>This ended up creating extra work/mess without any noticeable difference to me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=948c42d1e6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chocolate Almond Cake with Orange Marmalade]]></title>
            <link>https://medium.com/@freeformz/chocolate-almond-cake-with-orange-marmalade-43dd65d8abc?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/43dd65d8abc</guid>
            <category><![CDATA[cake]]></category>
            <category><![CDATA[baking]]></category>
            <category><![CDATA[almond-flour]]></category>
            <category><![CDATA[chocolate]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Wed, 28 Mar 2018 02:47:24 GMT</pubDate>
            <atom:updated>2018-03-28T02:47:24.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tif5JzoenOTLAIkFlcI1lw@2x.jpeg" /></figure><p>Chocolate Almond Cake with Orange Marmalade</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43dd65d8abc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[dep 101]]></title>
            <link>https://medium.com/i-can-haz-downtime/dep-101-c85e8ab6ed45?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c85e8ab6ed45</guid>
            <category><![CDATA[golang-tools]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Thu, 09 Feb 2017 15:46:58 GMT</pubDate>
            <atom:updated>2017-02-09T15:58:11.894Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve had the pleasure of working with several other gophers the last few months on a prototype dependency management tool named <a href="http://github.com/golang/dep">dep</a>.</p><p>dep is part of the project started <a href="https://groups.google.com/d/msg/go-package-management/YD8d5MtOf8g/LjqwWfXnBwAJ">last year</a> and is organized by <a href="https://peter.bourgon.org/">Peter Bourgon</a>. I was asked to join the team working on this project due to my involvement in a different tool, “<a href="https://github.com/tools/godep">godep</a>”, the OG dependency management tool for <a href="https://golang.org/">Go</a>, (inherited from <a href="https://github.com/kr">Keith Rarick</a>) and my work at <a href="https://heroku.com/">Heroku</a> serving our customers who use <a href="https://heroku.com/go">Go</a>.</p><p>The other members of the team, aside from myself and Peter, are <a href="https://twitter.com/jessfraz">Jessie Frazelle</a>, <a href="https://twitter.com/enneff">Andrew Gerrand</a> and <a href="https://twitter.com/sdboyer">Sam Boyer</a>. Andrew is part of the Go team @ Google. Jessie works at Google and is involved in large Go projects such as <a href="https://github.com/docker/docker/commits?author=jessfraz">Docker</a> and <a href="https://github.com/kubernetes/kubernetes/commits?author=jessfraz">Kubernetes</a>. Sam wrote and maintains <a href="https://github.com/sdboyer/gps">gps</a>, the constraint solver powering dep.</p><p>The team has <a href="https://groups.google.com/d/msg/go-package-management/VF_3It_DMwU/4ie8mmVEBQAJ">published</a> a <a href="https://groups.google.com/d/msg/go-package-management/g6EZblA1mHU/Sy_hGqCsBAAJ">bunch</a> of <a href="https://groups.google.com/d/msg/go-package-management/et1qFUjrkP4/Jp0T7l3uBAAJ">info</a> about our progress over the course of our work. To date, various other tool authors and concerned parties have also been involved in different ways.</p><p><strong>NOTE:</strong> dep is pre-alpha, so anything below may or may not be true moments after this blog post is published. However, I will try to keep it up-to-date as development continues.</p><h4>In the beginning…</h4><p>Let’s take dep for a drive and pretend we’re writing a web application using github.com/gorilla/mux. <a href="https://github.com/freeformz/depExample/blob/4bd5b5c5cc2be0206b5879b4f0a0527bd390f89a/main.go">Here</a> is some pretend code to get us started:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1cfd109a3460bdbfbcfe6f6894af2cf/href">https://medium.com/media/f1cfd109a3460bdbfbcfe6f6894af2cf/href</a></iframe><p>The first thing to do after writing some code, or when using dep for the first time on an existing project is to run dep init.</p><p>dep init adds the current version of any of the project’s dependencies found in $GOPATH to the manifest.json file. Because I have github.com/gorilla/mux in my $GOPATH, the manifest.json file includes it. I recently ran go get -u github.com/gorilla/mux, so the version of github.com/gorilla/mux in my $GOPATH is at master. If the version in my $GOPATH matched a <a href="http://semver.org/">Semver</a> compatible tag (ex: v1.2.3), that tag’s name would have been used instead.</p><p>dep works across architectures and go versions. Using github.com/gorilla/mux with older versions of Go (&lt; 1.7.0) pulls in the github.com/gorilla/context package. When I last rango get -u github.com/gorilla/mux I was running Go 1.7.5 so the github.com/gorilla/context package is NOT in my $GOPATH. Because this could be a dependency necessary to compile the project, it is included in the lock.json file. In situations like these, if a dependent project has a semver compatible release tag, dep chooses the latest release. In this case that is <a href="https://github.com/gorilla/context/releases/tag/v1.1">v1.1</a> of github.com/gorilla/context.</p><p>Because github.com/gorilla/mux does not include a manifest.json file dep don’t know if github.com/gorilla/mux currently works with github.com/gorilla/context @ v1.1. Barring an override (see below), dep honors the constraints found in dependencies’ manifest.json files.</p><p>dep init includes all dependencies, analyzed recursively and the exact versions being used in the lock.json file.</p><p>For the <a href="https://github.com/freeformz/depExample/commit/b13054dd0a332e22a392951c5eb19b4e59453cca">example app</a>, this creates the following two files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/984f12d3f915bcf5ef3529237dace6ab/href">https://medium.com/media/984f12d3f915bcf5ef3529237dace6ab/href</a></iframe><h4>Ensuring the project can build</h4><p>After dep init is run, dep ensure <a href="https://github.com/freeformz/depExample/commit/259b580183b3698593a0aa89072f5e5b7838e646">should be run</a> to populate the vendor/ directory with a copy of packages required to build your project. This ensures that any of your project’s dependencies are included in the lock file and vendor directory. Any time you want to ensure that you have all of your dependencies recorded, run dep ensure.</p><h4>Adding another dependency</h4><p>You don’t have to do anything up front to add another dependency, just start using it in your code. When it’s time to check in your work though you need to run dep ensure to update the lock.json file and vendor/. This will lock the project to the latest released version of each dependency.</p><p>In the sample app I added a <a href="https://github.com/freeformz/depExample/commit/fa297a98fa5256b63404671494ecfca557a60d1b">sub package</a> math that can be used to add, subtract or retrieve a named value and a HTTPHandler that can be used in main.go. After writing that code adep ensurerun produced <a href="https://github.com/freeformz/depExample/commit/8c67df68b24be375eb0082f54810251ad46c61b1">these changes</a> to the lock.json file and the vendor/ directory.</p><h4>But what if the latest doesn’t work for me?</h4><p>If you need to specify a version, you can use the alternate form of the ensure command like so: dep ensure github.com/gorilla/mux@^1.3.0. That command modifies the manifest.json file, constraining dep to use ^v1.3.0 of github.com/gorilla/mux, resolves the dependency tree and updates the dependencies in vendor/ to reflect any differences resulting from the change. On the example application, that looks like <a href="https://github.com/freeformz/depExample/commit/00efe026ef7b56138d798d3696a4b679b7d5da6f">this</a> because dep has already chosen the latest available version, 1.3.0. Future updates (dep ensure -update) however will no longer track the master branch and instead use semver tagged releases ≥ 1.3.0 and &lt; 2.0.0.</p><p>dep mostly uses Rust’s cargo <a href="http://doc.crates.io/specifying-dependencies.html">operators</a> for selecting versions of dependencies. These include <a href="http://doc.crates.io/specifying-dependencies.html#caret-requirements">^</a>, <a href="http://doc.crates.io/specifying-dependencies.html#tilde-requirements">~</a> and <a href="http://doc.crates.io/specifying-dependencies.html#inequality-requirements">=</a>. To have a more restrictive, forward compatible match than ^ use ~. For example dep ensure github.com/com/gorilla/mux@~1.2.0 will match any version ≥ 1.2.0 and &lt; 1.3.0. To lock to a specific version use the = prefix (e.x. dep ensure github.com/com/gorilla/mux@=1.2.0). In the <a href="https://github.com/golang/dep/issues/225">future it’s planned</a> that dep will default to ^ when no prefix is specified.</p><h4>Keeping current</h4><p>To keep a project’s dependencies up to date use dep ensure -update, which updates all dependencies to the latest versions allowed by the constraints in manifest.json, ignoring the contents of lock.json. New versions are written to vendor/ and the appropriate meta data updated in lock.json.</p><p>In <a href="https://github.com/golang/dep/issues/202">the future</a> it should be possible to dep ensure -update a single dependency.</p><h4>Status</h4><p>When a dependency is missing, dep status tells you which project and which packages contained inside are missing. For instance, here is what dep status shows after <a href="https://github.com/freeformz/depExample/commit/c719d1ca8dddaf72e104e0207b767e26c415e0c5">this commit</a> to the example app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31d9e3e2e4026aa63bc5dc14b65061e6/href">https://medium.com/media/31d9e3e2e4026aa63bc5dc14b65061e6/href</a></iframe><p>When the project’s lock.json is up-to-date, the dep status command shows you a list of all dependencies, as projects, and for each:</p><ul><li>the constraint(s) applied</li><li>the selected version</li><li>the selected revision</li><li>the latest version or revision available</li><li>the number of packages used.</li></ul><p>After adding bolt to the sample project and running <a href="https://github.com/freeformz/depExample/commit/8c67df68b24be375eb0082f54810251ad46c61b1">dep ensure</a> to update lock.json and vendor/, dep status looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1e564ed3a54eb3e9434eedd65148807/href">https://medium.com/media/c1e564ed3a54eb3e9434eedd65148807/href</a></iframe><p>These two modes may be combined in the <a href="https://github.com/golang/dep/issues/161">future</a>.</p><h4>Removal</h4><p>dep remove &lt;dep&gt; removes the dependency from manifest.json, lock.json and vendor/, once it’s no longer used. Using the example app <a href="https://github.com/freeformz/depExample/commit/665a611a18e0f91aeac61ab74fe4340f2414a991">this commit</a> removes the usage of github.com/gorilla/mux from the application and the <a href="https://github.com/freeformz/depExample/commit/86119a49150ded092ea8e271eb9517d5a4affcb5">next commit</a> is the result of dep remove github.com/gorilla/mux. Because github.com/gorilla/mux is removed, github.com/gorilla/context is no longer needed and is also removed. If a dependency is still being used when dep remove is run, the command will fail. Removal can be forced with the -force flag, which results in the constraint being removed from manifest.json. However, since the dependency is still in use it&#39;s still listed in lock.json and copied into vendor/.</p><h4>In the future….</h4><p>We’re still in an experimental phase with dep, there are many <a href="https://github.com/golang/dep/issues">issues</a> open and much work to do still. I hope this post clearly showed you some examples of how the tool is expected to be used. This usage <a href="https://github.com/golang/dep/issues/213">may</a> change over time via community feedback and <a href="https://github.com/golang/dep/pulls">pull requests</a>. If you have some spare cycles and are interested in working on some Go tooling please drop by #vendor on <a href="https://invite.slack.golangbridge.org/">gopher slack</a> and pick up an issue or two to work on.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c85e8ab6ed45" width="1" height="1" alt=""><hr><p><a href="https://medium.com/i-can-haz-downtime/dep-101-c85e8ab6ed45">dep 101</a> was originally published in <a href="https://medium.com/i-can-haz-downtime">I Can Haz Downtime?</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State of Go 2016 Survey]]></title>
            <link>https://medium.com/@freeformz/state-of-go-2016-survey-9aa1756a299b?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aa1756a299b</guid>
            <category><![CDATA[surveys]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Wed, 08 Jun 2016 17:18:08 GMT</pubDate>
            <atom:updated>2016-09-29T20:11:29.146Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Update:</strong> <em>See the </em><a href="https://github.com/freeformz/StateOfGo"><em>raw results</em></a><em>, a google </em><a href="https://docs.google.com/spreadsheets/d/1peTY_lq8rRW2zsKjwhd8iwiFZP5AZSrCvbCc07mPOWA/edit?usp=sharing"><em>sheet of the results</em></a><em> and/or my Gophercon lightning talk </em><a href="http://go-talks.appspot.com/github.com/freeformz/talks/20160712_gophercon/talk.slide#1"><em>slides</em></a><em>.</em></p><p><strong>TL;DR</strong>: If you are interested in <a href="https://golang.org/">Go</a> please take a few minutes to fill out this <a href="http://bit.ly/StateOfGo2016">survey</a>. I’ll do a follow up with the results.</p><p>I’ve been wondering what most other gophers are up to these days, what tools are being used, what packages are popular, where are people deploying, etc.</p><p>Inspired by a <a href="https://invite.slack.golangbridge.org/">slack</a> conversation with <a href="https://github.com/dgryski">Damian Gryski</a> a few weeks ago I started putting together the <a href="http://bit.ly/StateOfGo2016"><strong>State of Go 2016 Survey</strong></a>.</p><p>Completing the survey should take 5–10 minutes and is anonymous, unless you choose to enter an email address at the end. Please contact me if you have any questions about or issues with the survey. Please help spread the word by sharing the link (<a href="http://bit.ly/StateOfGo2016">http://bit.ly/StateOfGo2016</a>) on your social networks, with co-workers, at meetups, etc.</p><p>The survey will run through the last day of talks at <a href="https://gophercon.com/">GopherCon Denver</a>, <strong>July 12th, 2016</strong>. I will propose a lightning talk for July 13th @ GopherCon and/or do a follow up blog post with the results later in July.</p><p>Thanks to the various community members who helped produce, polish and test this survey and specifically <a href="https://twitter.com/goinggodotnet">William Kennedy</a> &amp; <a href="https://twitter.com/enneff">Andrew Gerrand</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aa1756a299b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Variable Declarations: Slices]]></title>
            <link>https://medium.com/@freeformz/on-variable-declarations-slices-71f43374721e?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/71f43374721e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[code-review]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Thu, 11 Feb 2016 04:14:35 GMT</pubDate>
            <atom:updated>2017-01-31T01:03:27.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uihjRKIqa57EHkCDLEreBw.jpeg" /></figure><p>There are several different ways to declare <a href="https://golang.org/doc/effective_go.html#slices">slices in Go</a>.</p><p>IMO, there is an implied meaning to each of these different ways:</p><ol><li><strong>var foo []T</strong> : Declare a slice that the code is going to start appending an unknown number of items to and/or the number doesn’t matter.</li><li><strong>var foo = []T{ … }</strong> or <strong>foo := []T{ … }</strong> : Where <strong>…</strong> is a list of items of type T. Declare a slice where the code has already figured out how to fill it and it’s unlikely to change much or at all while referenced. Prefer the later. Also seen as <strong>return []T{ … }</strong>.</li><li><strong>foo := make([]T, &lt;len&gt;, &lt;cap&gt;)</strong> : Declare a slice of a known capacity which isn’t expected to be exceeded while appending or it’s the minimum capacity slice that will be used. Generally the shorter form w/o capacity (ex. <strong>make([]T, &lt;len&gt;)</strong>), should only be used when making a slice as the target of a copy or index range manipulation loop.</li></ol><p>I feel that these above meanings lead to easier to understand and consume code. I encourage people to consider this when declaring and using slices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71f43374721e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type, *Type, Receivers & Interfaces]]></title>
            <link>https://medium.com/@freeformz/type-type-receivers-interfaces-db660727f0c8?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/db660727f0c8</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Thu, 15 Oct 2015 17:07:35 GMT</pubDate>
            <atom:updated>2017-02-03T18:08:17.085Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eo-bMXJ2NmsJyOn9rhKMoQ.jpeg" /><figcaption><a href="http://www.florianklauer.de/">http://www.florianklauer.de/</a></figcaption></figure><p>I’ve recently seen a bit of confusion around types, pointers to types, receivers for the two and interfaces. I’m going to try to clarify that confusion a bit with some examples.</p><p>Given a simple interface named <strong>Fooer</strong>, a struct type (<strong>Bar</strong>) that implements it and a simple function (<strong>DoFoo()</strong>) that accepts a <strong>Fooer</strong> and calls the interface function like so:</p><p><a href="https://play.golang.org/p/QDpxG41xqK">see this code in play.golang.org</a></p><pre>package main</pre><pre>import “fmt”</pre><pre>type Fooer interface {<br> Foo() int<br>}</pre><pre>type Bar struct{}</pre><pre>func (b Bar) Foo() int {<br> return 5<br>}</pre><pre>func DoFoo(f Fooer) {<br> fmt.Println(“Fooer:”, f.Foo())<br>}</pre><pre>func main() {<br> b := Bar{}<br> DoFoo(b)<br>}</pre><p>When you run the code above you get the following output:</p><blockquote>Fooer: 5</blockquote><h3>What’s happening?</h3><p><strong>Bar</strong> implements <strong>Foo() int</strong> so instances of it match the <strong>Fooer</strong> interface. If you change <strong>Bar{}</strong> to <strong>&amp;Bar{}</strong> to create a pointer to a <strong>Bar</strong>, the <a href="https://play.golang.org/p/M54OuYH9CU">program</a> runs and still works. This is because, as per the <a href="https://golang.org/ref/spec#Method_sets">GoSpec</a>: <em>pointer type *T is the set of all methods declared with receiver *T or T (that is, it also contains the method set of T)</em>. Since <strong>Foo()</strong> is declared on <strong>Bar</strong>, both an instance of <strong>Bar</strong> (<strong>Bar{}</strong>) and a pointer to an instance of <strong>Bar</strong> (<strong>&amp;Bar{}</strong>) have the method <strong>Foo() int</strong>.</p><p>Right now <strong>Foo()</strong> isn’t doing anything interesting though, just returning the integer <strong>5</strong>.</p><h3>More interesting</h3><p>Let’s modify the program a little so that <strong>Foo()</strong> actually does something: increment and return the value of a struct member like so:</p><p><a href="https://play.golang.org/p/yq9ImtGT0j">see this code in play.golang.org</a></p><pre>package main</pre><pre>import “fmt”</pre><pre>type Fooer interface {<br> Foo() int<br>}</pre><pre>type Bar struct {<br> val int<br>}</pre><pre>func (b Bar) Foo() int {<br> b.val++<br> return b.val<br>}</pre><pre>func DoFoo(f Fooer) {<br> fmt.Println(“Fooer:”, f.Foo())<br>}</pre><pre>func main() {<br> b := Bar{}<br> DoFoo(b)<br> DoFoo(b)<br>}</pre><p>Run the program. It may not output what you expected. You may have expected the second call to <strong>DoFoo</strong> to output “Fooer: 2&quot;, but instead “Fooer: 1” was output both times.</p><p>This happened because <strong>Foo()</strong> is declared on <strong>Bar</strong> (the non pointer version) and <strong>Foo()</strong>’s receiver is a copy of the <strong>Bar</strong> that was passed to <strong>DoFoo</strong>.</p><p>All parameters, including receivers, are pass by value and are copies of the original (<em>this includes pointers btw, they are just copies of the pointer itself</em>). Since it’s a copy, we always start out with the initial value of <strong>val</strong>, which is <strong>0</strong>.</p><p>So would changing <strong>Bar{}</strong> to <strong>&amp;Bar{}</strong> fix the problem? No, because even though <strong>*Bar</strong> contains all of the methods defined on <strong>Bar</strong>, they’re still called with a copy of the <strong>Bar</strong> instance since they are declared as being <em>on</em> <strong>Bar</strong>.</p><p><a href="https://play.golang.org/p/NzGEH0om_u">see this code in play.golang.org</a></p><pre>package main</pre><pre>import “fmt”</pre><pre>type Fooer interface {<br> Foo() int<br>}</pre><pre>type Bar struct {<br> val int<br>}</pre><pre>func (b Bar) Foo() int {<br> b.val++<br> return b.val<br>}</pre><pre>func DoFoo(f Fooer) {<br> fmt.Println(“Fooer:”, f.Foo())<br>}</pre><pre>func main() {<br> b := &amp;Bar{}<br> DoFoo(b)<br> DoFoo(b)<br>}</pre><p>To fix, we need to declare both <strong>Foo()</strong> on <strong>*Bar</strong> <em>AND</em> pass a <strong>*Bar</strong> to <strong>DoFoo</strong>. With this change an instance of <strong>Bar</strong> no longer matches the <strong>Fooer</strong> interface, but a pointer to <strong>Bar</strong> (<strong>*Bar</strong>) does and works like so:</p><p><a href="https://play.golang.org/p/gOT_oyV327">see this code in play.golang.org</a></p><pre>package main</pre><pre>import “fmt”</pre><pre>type Fooer interface {<br> Foo() int<br>}</pre><pre>type Bar struct {<br> val int<br>}</pre><pre>func (b *Bar) Foo() int {<br> b.val++<br> return b.val<br>}</pre><pre>func DoFoo(f Fooer) {<br> fmt.Println(“Fooer:”, f.Foo())<br>}</pre><pre>func main() {<br> b := &amp;Bar{}<br> DoFoo(b)<br> DoFoo(b)<br>}</pre><h3>Fin</h3><p>I hope these examples help clear up confusion and show the relationships between T, *T, receivers and interfaces.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db660727f0c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Go Apps to Heroku with Docker]]></title>
            <link>https://medium.com/@freeformz/deploying-go-apps-to-heroku-with-docker-51cdca5237eb?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/51cdca5237eb</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Mon, 05 Oct 2015 22:05:10 GMT</pubDate>
            <atom:updated>2016-04-11T16:43:38.910Z</atom:updated>
            <content:encoded><![CDATA[<p>This post covers using the <a href="https://github.com/heroku/heroku-docker">heroku docker</a> cli plugin to deploy a <a href="https://golang.org/">Go</a> application to <a href="https://heroku.com/">Heroku</a>. Only Linux and MAC OSX are supported until <a href="https://docs.docker.com/compose/">docker-compose</a> supports MS Windows.</p><h3>Prerequisites</h3><p>Please take a look at the links above and make sure everything is installed as per the linked instructions.</p><h3>Getting Started</h3><p>Start by cloning the <a href="https://github.com/heroku-examples/go-websocket-chat-demo">Go Websocket Chat Demo</a> Heroku application, a simple websocket application using redis to pass messages between processes:</p><pre>$ git clone <a href="https://github.com/heroku-examples/go-websocket-chat-demo.git">https://github.com/heroku-examples/go-websocket-chat-demo.git</a> <br>$ cd go-websocket-chat-demo</pre><p><strong>Note</strong>: It doesn’t matter where the code is located for this exercise as we’ll be doing everything inside of a docker container that will setup a $GOPATH for you.</p><p>The application is already prepared for Heroku as it contains both a <a href="https://devcenter.heroku.com/articles/procfile">Procfile</a>, which tells Heroku what to run, and an <a href="https://devcenter.heroku.com/articles/app-json-schema">app.json</a> file containing meta-data about the app.</p><p>In the case of Heroku Docker, the important part of the app.json file is the image, mount_dir &amp; addons keys, as seen below:</p><pre>{ &quot;name&quot;: &quot;Go Websocket Chat Demo&quot;, &quot;image&quot;: &quot;heroku/go:1.5&quot;, &quot;mount_dir&quot;: &quot;src/github.com/heroku-examples/go-websocket-chat-demo&quot;, &quot;repository&quot;: &quot;http://github.com/heroku-examples/go-websocket-chat-demol&quot;, &quot;addons&quot;: [ &quot;heroku-redis&quot; ] }</pre><p>The image key is used to determine which docker image to use. The mount_dir key is used to determine where to mount your source code for the interactive docker-compose run shell target (more on that later). And the addons key tells Heroku which <a href="https://addons.heroku.com/">Addons</a> the application requires. The <a href="https://github.com/heroku/heroku-docker/blob/master/lib/addons.js">addons currently supported</a> by the Heroku Docker CLI plugin are: <a href="https://addons.heroku.com/heroku-postgresql">Heroku Postgresql</a> (heroku-postgresql), <a href="https://addons.heroku.com/heroku-redis">Heroku Redis</a> (heroku-redis), <a href="https://addons.heroku.com/rediscloud">Redis Cloud</a> (rediscloud), <a href="https://addons.heroku.com/mongolab">Mongolab</a> (mongolab) &amp; <a href="https://addons.heroku.com/memcachedcloud">Memcached Cloud</a> (memcachedcloud). Supported addons will be attached to your container and created on your heroku application if they don’t exist during docker:release.</p><p>Given this configuration we can initialize the app with the following command:</p><pre>$ heroku docker:init</pre><p>This creates two files: Dockerfile &amp; docker-compose.yml. The Dockerfile is simple and just specifies the base heroku/go docker image. The docker-compose.yml file describes the containers required to run the application locally based on your addons and the contents of your Procfile.</p><h3>Run Locally</h3><p>Run the following command to start the application and it’s dependencies in local containers:</p><pre>$ docker-compose up web</pre><p>The first time this runs the docker images required to run the containers are constructed by pulling the required images from <a href="https://hub.docker.com/">Docker Hub</a>. These images are cached locally for re-use. The code is then copied into the container and compiled.</p><p>When the container is finished starting you’ll see some output like this:</p><pre>$ docker-compose up web ... web_1 | [negroni] listening on :8080 ... herokuRedis_1 | 1:M 28 Aug 21:05:40.442 * The server is now ready to accept connections on port 6379 web_1 | time=&quot;2015-08-28T21:06:36Z&quot; level=info msg=&quot;Redis Subscription Received&quot; channel=chat count=1 kind=subscribe</pre><p>Open the app in a browser by running:</p><pre>$ open <a href="http://$(docker-machine/">http://$(docker-machine</a> ip default):8080</pre><p>Your web application and redis database are containerized, running inside your local Docker environment, connected to each other via Docker Compose, creating a sort of “local cloud” on your machine.</p><h3>Deploying to Heroku</h3><p>Create a Heroku application like so:</p><pre>$ heroku create Creating peaceful-tor-8674... done, stack is cedar-14 <a href="https://peaceful-tor-8674.herokuapp.com/">https://peaceful-tor-8674.herokuapp.com/</a> | <a href="https://git.heroku.com/peaceful-tor-8674.git">https://git.heroku.com/peaceful-tor-8674.git</a> Git remote heroku added</pre><p>Deploy the application to Heroku using the following command:</p><pre>$ heroku docker:release Remote addons: (0) Local addons: heroku-redis (1) Missing addons: heroku-redis (1) Provisioning heroku-redis... Creating local slug... Building web... Step 0 : FROM heroku/go:1.5 # Executing 2 build triggers Trigger 0, COPY . /app/.temp Step 0 : COPY . /app/.temp Trigger 1, RUN /app/.cache/gotools/bin/compile Step 0 : RUN /app/.cache/gotools/bin/compile ---&gt; Running in 0db7ad69945e godep go install -tags heroku ./... ---&gt; 53f3c75d186c Removing intermediate container 0db7ad69945e Removing intermediate container edb3fca8865a Successfully built 53f3c75d186c extracting slug from container... creating remote slug... language-pack: heroku-docker (heroku/go:1.5) remote process types: { web: &#39;cd /app/user/src/github.com/heroku-examples/go-websocket-chat-demo &amp;&amp; go-websocket-chat-demo-web&#39; } uploading slug [====================] 100% of 3 MB, 0.0s releasing slug... Successfully released peaceful-tor-8674!</pre><p>That’s it! You’ll notice that a heroku-redis addon was added to the application because we haven’t added one yet and it’s an addon listed in the app.json file.</p><p><strong>NOTE</strong>: Sometimes the heroku-redis instance isn’t immediately available. You can check availability with heroku redis, looking at the Status field. If the app started before the database is available messages sent via the web interface will not show up in the chat log and you will need to restart the application (heroku restart) after the redis isntance is available.</p><p>Open the website and talk to yourself and share the link with someone else to chat with them.</p><pre>$ heroku open</pre><h3>A Local Shell</h3><p>The plugin configures a shell process that you can use to get shell access to containers running your app. This is similar to <a href="https://devcenter.heroku.com/articles/one-off-dynos">one-off dynos</a> on Heroku, and is handy for completing administrative tasks like database tasks, package vendoring, testing, etc.</p><p>You can also get a local shell into your application as well with:</p><pre>$ docker-compose run shell Building shell... <br>Step 0 : FROM heroku/go:1.5 # Executing 2 build triggers Trigger 0, COPY . /app/.temp<br>Step 0 : COPY . /app/.temp ---&gt; Using cache Trigger 1, RUN /app/.cache/gotools/bin/compile <br>Step 0 : RUN /app/.cache/gotools/bin/compile ---&gt; Using cache ---&gt; 53f3c75d186c<br>root@3a1d7501c029:~/user/src/github.com/heroku-examples/go-websocket-chat-demo #</pre><p>The shell container mounts your local working directory into the Docker container where it needs to be inside of a $GOPATH. Any changes that happen outside of that directory and it’s sub directories are however lost when the shell exits.</p><h3>Wrap Up</h3><p><a href="https://devcenter.heroku.com/articles/docker">Heroku’s Docker support</a> is currently in beta. As we work to make the integration better, we’d love to hear your feedback so we can focus on building the things you need. Feel free to reach out to me directly with you thoughts and ideas.</p><p>You can visit the Heroku Dev Center for more information on <a href="https://github.com/heroku/heroku-docker">Heroku’s Docker CLI</a>. And you can learn more about <a href="https://www.docker.com/">Docker</a> from their <a href="https://docs.docker.com/">documentation</a> site. You can also find more information about deploying <a href="https://golang.org/">Go</a> apps to Heroku on the <a href="https://devcenter.heroku.com/categories/go">Dev Center</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51cdca5237eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go 1.5's vendor/ experiment]]></title>
            <link>https://medium.com/@freeformz/go-1-5-s-vendor-experiment-fd3e830f52c3?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd3e830f52c3</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Thu, 09 Jul 2015 21:53:16 GMT</pubDate>
            <atom:updated>2015-10-05T22:06:28.274Z</atom:updated>
            <content:encoded><![CDATA[<p>Go currently (pre 1.5) doesn’t provide any built in method for <a href="https://groups.google.com/forum/m/#!topic/golang-dev/nMWoEAG55v8">vendoring</a> packages. The tools that currently exist today (<a href="http://github.com/tools/godep">godep</a>, <a href="https://github.com/jingweno/nut">nut</a> and a few others) basically exploit the implementation details of <strong><em>$GOPATH</em></strong>. Go 1.5 however includes a “vendor experiment”. With this experiment `<strong><em>go</em></strong>` commands will attempt to resolve dependencies in `<strong><em>vendor/</em></strong>` directories.</p><p>Russ Cox explains it fairly well in his <a href="https://github.com/golang/go/commit/183cc0cd41f06f83cb7a2490a499e3f9101befff">commit message</a>:</p><pre>If there is a source directory d/vendor, then, 	when compiling a source file within the subtree rooted at d, 	import &quot;p&quot; is interpreted as import &quot;d/vendor/p&quot; if that exists.<br><br>	When there are multiple possible resolutions, 	the most specific (longest) path wins.<br><br>	The short form must always be used: no import path can 	contain “/vendor/” explicitly.<br><br>	Import comments are ignored in vendored packages.</pre><p>To utilize this feature you need to set the environment variable `<strong>GO15VENDOREXPERIMENT</strong>` to `<strong>1</strong>` before running any of the go commands (<strong><em>run</em></strong>, <strong><em>test</em></strong>, <strong><em>build</em></strong>, <strong><em>install</em></strong>, etc)</p><p>For instance given a source tree like <a href="https://github.com/freeformz/go15vendorexample">this</a>:</p><pre>./main.go<br>./vendor<br>./vendor/a<br>./vendor/a/a.go<br>./vendor/b<br>./vendor/b/b.go<br>./vendor/c<br>./vendor/c/c.go<br>./vendor/c/vendor<br>./vendor/c/vendor/a<br>./vendor/c/vendor/a/a.go</pre><p>In this example I have <strong><em>main.go</em></strong> requiring all of the packages like so:</p><pre>package main</pre><pre>import (<br> “a”<br> “b”<br> “c”<br> “fmt”<br>)</pre><pre>func main() {<br> fmt.Println(“main.main()”)<br> fmt.Println(“main: a.A ==“, a.A)<br> fmt.Println(&quot;main: a.Inc() ==&quot;, a.Inc())<br> fmt.Println(“main: b.B ==“, b.B)<br> fmt.Println(“main: c.C ==“, c.C)<br>}</pre><p><strong><em>vendor/a/a.go</em></strong> looks like:</p><pre>package a</pre><pre>import “fmt”</pre><pre>var A = 1</pre><pre>func Inc() int {<br> A++<br> return A<br>}</pre><pre>func init() {<br> fmt.Println(“Init package a”)<br> fmt.Println(“a: A ==“, A)<br>}</pre><p><strong><em>vendor/b/b.go</em></strong> looks like:</p><pre>package b</pre><pre>import “a”<br>import “fmt”</pre><pre>var B = 2</pre><pre>func init() {<br> fmt.Println(“Init package b”)<br> fmt.Println(“b: a.A ==“, a.A)<br> fmt.Println(“b: a.Inc() ==“, a.Inc())<br>}</pre><p><strong><em>vendor/c/c.go</em></strong> looks like:</p><pre>package c</pre><pre>import “a”<br>import “fmt”</pre><pre>var C = 3</pre><pre>func init() {<br> fmt.Println(“Init package c”)<br> fmt.Println(“c: C ==“, C)<br> fmt.Println(“c: a.A ==“, a.A)<br> fmt.Println(“c: a.Inc() ==“, a.Inc())<br>}</pre><p>and lastly <strong><em>vendor/c/vendor/a/a.go</em></strong> looks like:</p><pre>package a</pre><pre>import “fmt”</pre><pre>var A = 100</pre><pre>func Inc() int {<br> A++<br> return A<br>}</pre><pre>func init() {<br> fmt.Println(“Init c/vendor/a”)<br> fmt.Println(“c/vendor/a: A ==“, A)<br>}</pre><p>Running <strong><em>main.go</em></strong> without the vendor experiment produces what you would expect:</p><pre>$ go run main.go<br>main.go:4:2: cannot find package “a” in any of:<br> /usr/local/go/src/a (from $GOROOT)<br> /Users/emuller/go/src/a (from $GOPATH)<br>main.go:5:2: cannot find package “b” in any of:<br> /usr/local/go/src/b (from $GOROOT)<br> /Users/emuller/go/src/b (from $GOPATH)<br>main.go:6:2: cannot find package “c” in any of:<br> /usr/local/go/src/c (from $GOROOT)<br> /Users/emuller/go/src/c (from $GOPATH)</pre><p>But running <strong><em>main.go</em></strong> with the vendor experiment turned on produces:</p><pre>$ GO15VENDOREXPERIMENT=1 go run main.go<br>Init package a<br>a: A == 1<br>Init package b<br>b: a.A == 1<br>b: a.Inc() == 2<br>Init c/vendor/a<br>c/vendor/a: A == 100<br>Init package c<br>c: C == 3<br>c: a.A == 100<br>c: a.Inc() == 101<br>main.main()<br>main: a.A == 2<br>main: a.Inc() == 3<br>main: b.B == 2<br>main: c.C == 3</pre><p>Let’s unpack that a little….</p><p><strong><em>main.go</em></strong> imports all three top level dependencies: <strong><em>a</em></strong>, <strong><em>b</em></strong> &amp; <strong><em>c</em></strong>.</p><p>Each of those dependencies uses an <a href="https://golang.org/doc/effective_go.html#init"><strong><em>init</em></strong> func</a>tion for demonstration purposes. As each <strong><em>init</em></strong> function is executed it prints out its exported variable. When it imports package <strong><em>a</em></strong> it also calls <strong><em>a</em></strong>’s exported <strong><em>Inc</em></strong> function so we can observe a side effect.</p><p>First we see package <strong><em>a</em></strong> being initialized:</p><pre>Init package a<br>a: A == 1</pre><p>Then we see package <strong><em>b</em></strong> being initialized:</p><pre>Init package b<br>b: a.A == 1<br>b: a.Inc() == 2</pre><p>Package <strong><em>b</em></strong> imports package <strong><em>a</em></strong> and because of the dependency resolution policy of longest path wins (see Russ’ comment above) <strong><em>vendor/a</em></strong> is what is used. <strong><em>a.Inc</em></strong> is called, which increments <strong><em>a</em></strong>’s internal variable.</p><p>Then we see package <strong><em>c</em></strong> being initialized:</p><pre>Init c/vendor/a<br>c/vendor/a: A == 100<br>Init package c<br>c: C == 3<br>c: a.A == 100<br>c: a.Inc() == 101</pre><p>Package <strong><em>c</em></strong> also imports a package <strong><em>a</em></strong>, but unlike package <strong><em>b</em></strong> it has its own version of a package <strong><em>a</em></strong> inside of its own vendor directory making the full path to the package <strong><em>a</em></strong> that package <strong><em>c</em></strong> imports being: <strong><em>vendor/c/vendor/a</em></strong>. This new package <strong><em>a</em></strong> has a different value for its internal variable (100) and calling <strong><em>a.Inc</em></strong> updates it to 101.</p><p>Lastly main’s <strong><em>main</em></strong> function runs:</p><pre>main.main()<br>main: a.A == 2<br>main: a.Inc() == 3<br>main: b.B == 2<br>main: c.C == 3</pre><p>Showing that the package <strong><em>a</em></strong> used by <strong><em>main</em></strong> is the one in <strong><em>vendor/a</em></strong>, not the one in <strong><em>vendor/c/vendor/a</em></strong> or vice versa.</p><h3>Recursion!</h3><p>One interesting side effect of this experimental implementation is that it’s recursive in nature, meaning libraries with dependencies can vendor their own dependencies inside their own vendor directory and the go tooling handles it.</p><h3>Side Effects + Gotchas</h3><p>Multiple versions of the same library will cause problems. For instance, only a single copy of any database/sql driver can be registered, if you vendor lib/pq and another vendored dep also vendors it and imports it, you’ll get a panic. This is a limitation of database/sql, but probably also a sane one. Another <a href="https://github.com/golang/go/issues/11634">issue</a> (hat tip to <a href="http://onetruekarl.com/">onetruekarl</a>) comes up when 2 vendored dependencies also vendor their own copies of another depencency with the same name. If any of those sub types bubble out of the libraries that you’ve vendored you won’t be able to tell which vendored package it actually comes from.</p><p>Tools like <a href="http://github.com/tools/godep">godep</a>, <a href="https://github.com/kardianos/vendor">vendor</a>, <a href="https://github.com/constabulary/gb">gb</a>, etc may be called upon to “squash” down recursively vendored packages into a single version in the <strong><em>vendor/</em></strong> directory. It’s not really clear what people’s expectations here are though.</p><p>There is a strong argument to be made that libraries should not vendor their own dependencies, but as the author of several library / command combo packages that rely extensively on 3rd party libraries I’m not convinced of that blanket assertion.</p><p>Determining the proper versions without a bunch of extra metadata around will be hard. This is probably a place where the <a href="https://github.com/kardianos/vendor-spec">vendor-spec</a> comes in handy.</p><p>In any case I am looking forward to the official support for this.</p><p><em>Originally published at </em><a href="http://icanhazdowntime.org/post/2015-07-09-go-vendor-experiment/"><em>icanhazdowntime.org</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd3e830f52c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I like Go]]></title>
            <link>https://medium.com/@freeformz/why-i-like-go-1b10857f6728?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b10857f6728</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Wed, 24 Jun 2015 00:48:13 GMT</pubDate>
            <atom:updated>2017-07-26T16:03:17.898Z</atom:updated>
            <content:encoded><![CDATA[<p>originally posted at <a href="https://gist.github.com/freeformz/4746274">https://gist.github.com/freeformz/4746274</a></p><p>I visited with PagerDuty a long while ago for a little Friday beer and pizza. While there I got started talking about Go. I was asked by <a href="https://twitter.com/alxsolomon">Alex</a>, their CEO, why I liked it. Several other people have asked me the same question recently, so I figured it was worth posting.</p><h3>Goroutines</h3><p>The first 1/2 of Go’s concurrency story. Lightweight, concurrent function execution. You can spawn tons of these if needed and the Go runtime multiplexes them onto the configured number of threads as needed. They start with a super small stack that can grow (and shrink) via dynamic allocation (and freeing). They are as simple as:</p><pre><a href="https://golang.org/ref/spec#Go_statements">go</a> f(x)</pre><p>where <strong>f()</strong> is some function.</p><h3>Channels</h3><p>The other 1/2 of Go’s concurrency story. <a href="https://golang.org/ref/spec#Channel_types">Channels</a> are a typed conduit used to send and receive values, usually between goroutines. By default they are unbuffered, meaning synchronous and blocking. But they can also be buffered, allowing values to queue up for processing. Multiple go routines can read/write from/to them at the same time w/o having to take locks (although the channel locks handles the locks internally). You can also read or write to/from multiple channels simultaneously via the <a href="https://golang.org/ref/spec#Select_statements">select statement</a>.</p><h3>Compiled</h3><p>Go can compile your program into a <strong>static binary</strong>. Yep, you read that correctly: <strong>a static binary</strong>. This makes deployment really simple, just copy over the binary. No bundler, no virtualenv, etc. All of that is handled at compile time. This greatly simplifies deployment.</p><h3>Runtime</h3><p>Go is a compiled language, but still has a runtime. It handles all of the details of allocating memory for you. Memory used by variables lasts as long as the variables are referenced, which is usually the scope of a function. Go has a garbage collector.</p><h3>Pass By Value</h3><p>Everything is passed by value, but there are pointers. It’s just that the value of a pointer is a memory location, so it acts as pass by reference. So you can pass a pointer if you desire/need it for performance/memory utilization reasons. Go does the right thing by default, but doesn’t shackle you. Oh, and there isn’t any pointer math, so you won’t screw yourself with it.</p><p>As pointed out on <a href="http://news.ycombinator.com/item?id=5196498">HN</a>, you can do pointer math with the <a href="http://golang.org/pkg/unsafe/">“unsafe”</a> package and unsafe.Pointer.</p><h3>Type System</h3><p>Go has structs and interfaces. Go’s structs can have methods <em>associated</em> with them. Structs can be anonymously included in other structs to make the inside struct’s variables/methods available as part of the enclosing struct. Interfaces are sets of method signatures. Structs implement an interface by implementing the methods described by the interface definition. Functions can receive values by interface, like <a href="http://play.golang.org/p/KfKLiAClQE">so</a>. The compiler checks all of this at compile time.</p><h3>Package System</h3><p>Or <strong><em>lack</em></strong> there of. Since Go compiles everything statically, you don’t have to worry about packages at runtime. But how do you include libraries into your code? Simply by importing them via url, like so:</p><pre>import “github.com/bmizerany/pq”</pre><p>Go’s tooling knows how to look that up and clone the repo and also works with Mercurial, Bazaar &amp; Subversion.</p><p>Reproducible builds are made possible via vendoring dependencies inside you application’s repo either manually or with tools like <a href="http://github.com/tools/godep">godep</a>, <a href="https://github.com/constabulary/gb">gb</a> or <a href="https://github.com/kardianos/vendor">vendor</a>.</p><p>The next version of Go (1.5) will have an option (“<em>-vendor”</em>) that removes some of the hurdles the above tools need to currently go through.</p><h3>Anonymous Functions &amp; Closures</h3><p>Go supports anonymous functions that can form closures. These functions can then be passed around and retain the environment under which they were created, like <a href="http://play.golang.org/p/4rYrqw4l7m">so</a>. This can be super powerful when <a href="https://github.com/freeformz/filechan">combined</a> with channels and goroutines.</p><h3>Built in profiling</h3><p>It supports pprof as part of the standard library. And with a <a href="http://golang.org/pkg/net/http/pprof/">very small bit of work</a>, you can access profiling info via a http interface.</p><p>]The next version of Go (1.5) will also support native <a href="https://go-review.googlesource.com/#/c/3601/">tracing</a>.</p><h3>Defer</h3><p>Ever forget to close a file descriptor or free some memory? So have the designers of Go. The reason for this is that you usually have to perform those actions far away from where the resources were opened/allocated. Go solves this problem with the <a href="http://blog.golang.org/defer-panic-and-recover">defer</a> statement. Each defer statement pushes a function/expression onto a stack that get’s executed in LIFO order after the enclosing function returns. This makes cleanup really easy. After opening a file, just “<strong>defer file.Close()”</strong>.</p><h3>Comprehensive Standard Library</h3><p>Go’s <a href="http://golang.org/pkg/">standard library</a> is pretty comprehensive.</p><h3>It’s Fast</h3><p>Go compiles down to native code and it does it fast, usually in just a few seconds.</p><h3>Comprehensive Tooling Out Of The Box</h3><p>Go run “<strong>go -help”</strong>. Some of my favorites: <strong>go fmt</strong>, <strong>go doc</strong>, <strong>go fix</strong>, <strong>go get</strong>, <strong>go tool pprof</strong> &amp; <strong>go test</strong>.</p><h3>Straight Forward Testing</h3><p>Super <a href="http://golang.org/pkg/testing/">straight forward</a>, no magic. Also <a href="https://github.com/golang/go/wiki/TableDrivenTests">table driven tests</a>!</p><h3>Simple C Interface</h3><p>By using build directives you can integrate with C libraries really <a href="https://gist.github.com/freeformz/4552031">easily</a>.</p><h3>Straight Forward Syntax w/ Standard Formatting</h3><p>The syntax is pretty simple, C like w/o all the crazy of C. But what’s really nice is “<strong>go fmt”</strong>, which re-writes your code into the Go standard format. No more arguments over coding style!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b10857f6728" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go + Heroku : Hello World]]></title>
            <link>https://medium.com/@freeformz/hello-world-with-go-heroku-38295332f07b?source=rss-f90e265567b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/38295332f07b</guid>
            <category><![CDATA[hello-world]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[freeformz]]></dc:creator>
            <pubDate>Fri, 17 Apr 2015 15:26:08 GMT</pubDate>
            <atom:updated>2015-10-05T22:07:33.780Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>NOTE: </em></strong><a href="https://blog.heroku.com/archives/2015/7/7/go_support_now_official_on_heroku"><strong><em>Heroku has launched official support for Go</em></strong></a><strong><em>.</em></strong></p><p>This is a quick start guide to deploying a simple “Hello World” <a href="http://golang.org/">Go</a> web application to <a href="http://heroku.com/">Heroku</a>. It is in no way comprehensive, but aims to provide links to supporting documentation. In many ways it is an updated version of the excellent <a href="https://mmcgrana.github.io/2012/09/getting-started-with-go-on-heroku.html">Getting Started With Go On Heroku</a> guide done by <a href="https://twitter.com/mmcgrana">Mark McGranaghan</a>.</p><p>The guide is command line centric and examples assume basic proficiency with a shell on a UNIX (OS X, Linux, etc) operating system.</p><h3>What is Go</h3><p><a href="https://golang.org/">Go</a> is an open source programming language with built-in concurrency primitives, type safety, fast compile time, automatic memory management and a comprehensive standard library. It’s fun to write and a great fit for web and other network services.</p><h3>Installing Go</h3><p>Install Go by following the installation instructions on the <a href="https://golang.org/doc/install">Go website</a> for your specific OS.</p><p>Once installed you should be able to open a console / terminal / command line prompt and run the following:</p><pre>$ go version<br>go version go1.4.2 darwin/amd64</pre><p>If you are having trouble installing go, you can find help on the <a href="https://groups.google.com/forum/#!forum/golang-nuts">golang-nuts</a> mailing list and/or the <a href="http://blog.gopheracademy.com/gophers-slack-community/">Gopher Slack Channel</a>.</p><h3>Go Workspace</h3><p>Go code is organized into a workspace rooted at <strong><em>$GOPATH</em></strong>. A workspace contains the source code for multiple go packages (<strong><em>$GOPATH/src/…</em></strong>) as well as compiled binaries (<strong><em>$GOPATH/bin</em></strong>) and intermediary compiled objects (<strong><em>$GOPATH/pkg/…</em></strong>). The go tooling expects your code to be arranged into one or more workspaces.</p><p>This is all detailed in the <a href="https://golang.org/doc/code.html">How To Write Go Code</a> document, but here is the TL;DR version:</p><pre>$ mkdir -p $HOME/go<br>$ export GOPATH=$HOME/go<br>$ export PATH=$GOPATH/bin:$PATH</pre><p>This sets the workspace to the directory <strong><em>$HOME/go</em></strong> and adds the workspace’s bin directory to your <strong><em>$PATH</em></strong> for the current shell.</p><p><strong><em>NOTE:</em></strong> From here on we expect <strong><em>$GOPATH</em></strong> and <strong><em>$PATH</em></strong> to be set as above.</p><h3>Hello World Web Application</h3><p>Start by creating the directory inside of <strong><em>$GOPATH</em></strong> that will hold the application’s source code:</p><pre>mkdir -p $GOPATH/src/helloworld</pre><p>Using your <a href="https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins">favorite editor</a> create <strong><em>$GOPATH/src/helloworld/main.go</em></strong> with the following content:</p><pre>package main</pre><pre>import (<br>  &quot;log&quot;<br>  &quot;fmt&quot;<br>  &quot;net/http&quot;<br>  &quot;os&quot;<br>)</pre><pre>func determineListenAddress() (string, error) {<br>  port := os.Getenv(&quot;PORT&quot;)<br>  if port == &quot;&quot; {<br>    return &quot;&quot;, fmt.Errorf(&quot;$PORT not set&quot;)<br>  }<br>  return &quot;:&quot; + port, nil<br>}</pre><pre>func hello(w http.ResponseWriter, r *http.Request) {<br>  fmt.Fprintln(w, &quot;Hello World&quot;)<br>}</pre><pre>func main() {<br>  addr, err := determineListenAddress()<br>  if err != nil {<br>    log.Fatal(err)<br>  }</pre><pre>  http.HandleFunc(&quot;/&quot;, hello)<br>  log.Printf(&quot;Listening on %s...\n&quot;, addr)<br>  if err := http.ListenAndServe(addr, nil); err != nil {<br>    panic(err)<br>  }<br>}</pre><p>The code above is pretty basic, consisting of just 3 methods:</p><ol><li><strong><em>main</em></strong> is the entry point into the application. It first tries to determine which address to listen on and if it can’t exits with an error. Otherwise <strong><em>hello</em></strong> is registered to handle all requests and listens on the address. If there is any problem listening on the address it panics, otherwise it starts servicing http requests.</li><li><strong><em>hello</em></strong> is the <a href="http://golang.org/pkg/net/http/#Handler">http.Handler</a> that ‘says’ “Hello World”.</li><li><strong><em>determineListenAddress</em></strong> figures out what address to listen on for traffic. It uses the <strong><em>$PORT</em></strong> environment variable only to determine this. If <strong><em>$PORT</em></strong> isn’t set an error is returned instead.</li></ol><p>Compile and install the code with:</p><pre>$ go install ./...</pre><p>Run the application with:</p><pre>$ PORT=5000 $GOPATH/bin/helloworld<br>Listening on 5000...</pre><p>Make a HTTP request to the application:</p><pre>$ curl -i <a href="http://localhost:5000/">http://localhost:5000/</a><br>HTTP/1.1 200 OK<br>Date: Wed, 15 Apr 2015 06:32:33 GMT<br>Content-Length: 12<br>Content-Type: text/plain; charset=utf-8</pre><pre>Hello World</pre><h3>Deploying To Heroku</h3><p>The application is running locally, so let’s deploy it to <a href="http://heroku.com/">Heroku</a>.</p><h4>Heroku Prerequisites</h4><ol><li><a href="https://signup.heroku.com/www-header">Sign up</a> for a Heroku account.</li><li>Install the <a href="https://devcenter.heroku.com/articles/heroku-command">Heroku Toolbelt</a>.</li><li>Login with <strong><em>heroku login</em></strong>.</li></ol><h4>Preparing the application</h4><p><a href="http://git-scm.com/">Git</a> is installed as part of the Heroku Toolbelt. We’ll use it to track and push the source code to Heroku.</p><pre>$ git init<br>$ git add -A .<br>$ git commit -m “Hello World”</pre><p>Heroku uses a file named <a href="https://devcenter.heroku.com/articles/procfile)"><strong><em>Procfile</em></strong></a> to determine what should be run. Let’s configure the <em>web</em> process type to execute the file named <strong><em>helloworld</em></strong>:</p><pre>$ echo “web: helloworld” &gt; Procfile<br>$ git add Procfile<br>$ git commit -m Procfile</pre><h4>Godep</h4><p>The supported way to manage dependencies for Go applications on Heroku is via <a href="https://github.com/tools/godep">Godep</a>. Install godep via:</p><pre>$ go get -u github.com/tools/godep</pre><p>Record and vendor any dependencies:</p><pre>$ godep save -r ./...<br>$ git add -A Godeps<br>$ git commit -m Godeps</pre><p>This saves a description of the dependencies to <strong><em>Godeps/Godeps.json</em></strong> and vendors the source code into <strong><em>Godeps/_workspace</em></strong> as well as rewrites any import directives to use those copies. This hello world application doesn’t have any dependencies outside of Go’s standard library and the <strong><em>Godeps/Godeps.json</em></strong> records that:</p><pre>$ cat Godeps/Godeps.json<br>{<br>    “ImportPath”: “helloworld”,<br>    “GoVersion”: “go1.4.2”,<br>    “Packages”: [<br>        “./…”<br>    ],<br>    “Deps”: []<br>}</pre><h4>Heroku Deploy</h4><p>Create a new Heroku app using the <a href="https://github.com/heroku/heroku-buildpack-go">Go Buildpack</a>:</p><pre>$ heroku create -b <a href="https://github.com/heroku/heroku-buildpack-go.git">https://github.com/heroku/heroku-buildpack-go.git</a><br>Creating sheltered-peak-9514... done, stack is cedar-14<br>Buildpack set. Next release on sheltered-peak-9514 will use <a href="https://github.com/heroku/heroku-buildpack-go.git">https://github.com/heroku/heroku-buildpack-go.git</a>.<br><a href="https://sheltered-peak-9514.herokuapp.com/">https://sheltered-peak-9514.herokuapp.com/</a> | <a href="https://git.heroku.com/sheltered-peak-9514.git">https://git.heroku.com/sheltered-peak-9514.git</a><br>Git remote heroku added</pre><p>The application name is randomly generated, so will differ from above.</p><p>Push the code to Heroku:</p><pre>$ git push heroku master<br>Counting objects: 13, done.<br>Delta compression using up to 4 threads.<br>Compressing objects: 100% (9/9), done.<br>Writing objects: 100% (13/13), 1.37 KiB | 0 bytes/s, done.<br>Total 13 (delta 0), reused 0 (delta 0)<br>remote: Compressing source files... done.<br>remote: Building source:<br>remote:<br>remote: — — -&gt; Fetching custom git buildpack… done<br>remote: — — -&gt; Go app detected<br>remote: — — -&gt; Installing go1.4.2... done<br>remote: — — -&gt; Running: godep go install -tags heroku ./...<br>remote: — — -&gt; Discovering process types<br>remote: Procfile declares types -&gt; web<br>remote:<br>remote: — — -&gt; Compressing... done, 1.6MB<br>remote: — — -&gt; Launching... done, v3<br>remote: <a href="https://sheltered-peak-9514.herokuapp.com/">https://sheltered-peak-9514.herokuapp.com/</a> deployed to Heroku<br>remote:<br>remote: Verifying deploy... done.<br>To <a href="https://git.heroku.com/sheltered-peak-9514.git">https://git.heroku.com/sheltered-peak-9514.git</a><br> * [new branch] master -&gt; master</pre><p>The applications is now running on Heroku. Open it in a browser:</p><pre>$ heroku open</pre><p>You can inspect the <a href="https://devcenter.heroku.com/articles/dynos">dyno(s</a>) running the application:</p><pre>$ heroku ps<br>=== web (1X): `helloworld`<br>web.1: up 2015/04/14 23:55:51 (~ 6m ago)</pre><p>And you can view requests that come in via the log stream:</p><pre>$ heroku logs --tail<br>...<br>2015–04–15T06:59:39.396139+00:00 heroku[router]: at=info method=GET path=”/” host=sheltered-peak-9514.herokuapp.com request_id=f5a7d634-dbf0–42c2-a278-e1dc37c98178 fwd=”76.115.27.201&quot; dyno=web.1 connect=0ms service=1ms status=200 bytes=148<br>...</pre><h3>Thanks</h3><p>Thanks to <a href="https://www.linkedin.com/in/michellepeot">Michelle Peot</a>, <a href="http://apgwoz.com/">Andrew Gwozdziewycz</a>, <a href="https://twitter.com/cyx">Cyril David</a> &amp; <a href="https://twitter.com/mmcgrana">Mark McGranaghan</a> for reviewing and making suggestions.</p><p><em>Originally published at </em><a href="http://icanhazdowntime.org/post/2015-04-17-go_plus_heroku_hello_world/"><em>icanhazdowntime.org</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38295332f07b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>