<?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[The Go Journey - Medium]]></title>
        <description><![CDATA[Various articles round and about working with our favorite programming language - Medium]]></description>
        <link>https://medium.com/the-go-journey?source=rss----74bea50445ff---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>The Go Journey - Medium</title>
            <link>https://medium.com/the-go-journey?source=rss----74bea50445ff---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 14:06:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/the-go-journey" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fetch Random Unsplash Images in Your Go Apps]]></title>
            <link>https://medium.com/the-go-journey/fetch-random-unsplash-images-in-your-go-apps-2a298463e6d2?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/2a298463e6d2</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 11:01:25 GMT</pubDate>
            <atom:updated>2021-01-21T11:01:25.861Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Read the original post for free at </em><a href="https://preslav.me/2021/01/11/an-easy-way-to-get-a-random-stream-of-images-in-your-golang-app/"><em>https://preslav.me</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lV-3w0aouUL6Toqe" /><figcaption>Photo by <a href="https://unsplash.com/@desola?utm_source=medium&amp;utm_medium=referral">Desola Lanre-Ologun</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Perhaps not known to everybody, <a href="https://unsplash.com/">Unsplash,</a> the free stock photography service, offers its own <a href="https://unsplash.com/developers">set of APIs</a>, one of which caught my attention in particular. As part of the project behind my <a href="https://preslav.me/generative-art-in-golang/">Generative Art in Go</a> book, I needed a way to obtain source image material without looking at it first. By blindly fetching an image, I could guarantee that the final art sketch would be a process of chaos + generative algorithm and not a subject to my decision.</p><p>I found the following URL to be a straightforward way to get a random source of beautiful imagery:</p><pre><a href="https://source.unsplash.com/random/[WIDTH]x[HEIGHT]">https://source.unsplash.com/random/[WIDTH]x[HEIGHT]</a></pre><p>I quickly set up the following Go function, which did all the magic for me:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gSqhSUZBpaXr9dSLSXy4A.png" /><figcaption>A function for loading random images from Unsplash</figcaption></figure><p>A function for loading random images from Unsplash</p><p><strong>Note:</strong> Of course, it goes without saying that we must respect Unsplash’s generous offering and not abuse it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a298463e6d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/fetch-random-unsplash-images-in-your-go-apps-2a298463e6d2">Fetch Random Unsplash Images in Your Go Apps</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go is Good Enough]]></title>
            <link>https://medium.com/the-go-journey/go-is-good-enough-5b88d7778bb?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/5b88d7778bb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Thu, 28 May 2020 10:13:08 GMT</pubDate>
            <atom:updated>2020-05-28T10:18:21.731Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you heard about the <a href="https://en.wikipedia.org/wiki/Pareto_principle">Pareto Principle</a>? Also known as the <em>80⁄20 Rule</em>, it states that for many aspects of life, 80% of the effects come from 20% of the inputs. Flip it around and the opposite is also true: reaching out for the rest of the 20% requires 80% of the initial effort. It is amazing how many manifestations of both exist in real life. One of the big wisdoms in life — it is often not the smartest, fastest, or strongest individuals that leave a dent. It is the ones pragmatic enough to achieve the 80% with 20% of the effort and energy spent.</p><p>The slight deviation aside, the same very much applies to the Go programming language. It is just good enough. Go won’t win the category of language design, neither is it the fastest one on the market. Nor is it the safest member of the bunch. The truth is, what Go offers on the table might seem pretty boring at first. It is a compiled, statically typed language with an extremely reduced syntax, a somewhat simplified concurrency model, and a bit of memory safety. Nothing near close to the speed of C, the beauty of Ruby or the dogmatic memory management of Rust.</p><p>And this is what makes Go succeed. It does not have any of those things, but it is simple and fast enough to get you going on a new project without having to second-guess your approach every second. The lack of features helps reduce the cognitive burden on both the programmer and the compiler. The speed, file-size and memory consumption of the final applications is more optimal than those of 80% of applications built using other technologies.</p><p>Will Go ever be the best in any single programming language category? Probably no. Is it good enough to sustain 80% of your programming efforts? Absolutely!</p><p><em>Originally published at </em><a href="https://preslav.me/2019/10/18/go-is-good-enough/"><em>https://preslav.me</em></a><em> on October 18, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b88d7778bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/go-is-good-enough-5b88d7778bb">Go is Good Enough</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Simplest Way to Keep a Go App Up and Running]]></title>
            <link>https://medium.com/the-go-journey/the-simplest-way-to-keep-a-go-app-up-and-running-1556b6fca1dd?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/1556b6fca1dd</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Sun, 24 May 2020 17:13:08 GMT</pubDate>
            <atom:updated>2020-05-24T17:29:54.692Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Simple Way to Keep a Go App Up and Running</h3><h4>Poor man’s Kubernetes</h4><p>I am a lazy programmer, experimenting with new ideas all the time. For these, running and deploying tiny Go apps as single executables is the closest way to see something in action. Yet, quickly written Go apps often panic, and crash altogether. While I am a strong defender of making sure that all possible errors are checked, real software is bound to eventually crash, no matter what. In such situations, the fastest solution is usually a simple restart.</p><p><a href="https://www.freedesktop.org/wiki/Software/systemd/">Systemd</a>, <a href="https://www.docker.com/">Docker</a>, <a href="https://kubernetes.io/">Kubernetes</a> — all took process supervision to a new level. If you are working on production-level software, chances are you already have some infrastructure layer in place that will take care of this. On the other hand, setting up tons of infrastructure is the last thing you want to think about, when working on your quickly made side project. This is where the following 5-line Bash script comes in place:</p><pre>#!/bin/sh</pre><pre>while true; do<br>    ./myapp<br>done</pre><pre># call this file run.sh and use nohup to start it<br># nohup ./run.sh &amp;</pre><p>That’s it. Instead of running your app directly, you can use nohup to run it through the Bash script: nohup run.sh &amp;.</p><p>NOTE: While fairly easy to set up, this is by no means a safe way to take care of process restarts. It is also not an excuse to avoid thorough error checking. It will help you see your app quickly, but as soon as it starts getting serious traffic, you need to consider setting up the proper infrastructure. I can <a href="https://preslav.me/contact/">help</a> with that.</p><p><em>Originally published at </em><a href="https://preslav.me/2020/05/24/the-simplest-way-to-keep-a-go-app-up-and-running/"><em>https://preslav.me</em></a><em> on May 24, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1556b6fca1dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/the-simplest-way-to-keep-a-go-app-up-and-running-1556b6fca1dd">The Simplest Way to Keep a Go App Up and Running</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I actually agree with this.]]></title>
            <link>https://medium.com/the-go-journey/i-actually-agree-with-this-ecbe6fa95785?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/ecbe6fa95785</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 20:24:56 GMT</pubDate>
            <atom:updated>2019-12-14T20:24:56.678Z</atom:updated>
            <content:encoded><![CDATA[<p>I actually agree with this. There have been a few occasions in my work, where I nudged people to write code that fails right away, rather than obfuscate the flow with passing errors backs, only to panic in the main goroutine.</p><p>In the Go community, there is some kind of paranoia around panicking, as if it’s the worst thing that can happen to your application. In fact, it often is the better option. Think about Go programs as CLI applications Would you rather crash right away and let the user react, or hang, trying to recover? The same applies to applications running as services. Modern tooling makes it easy to restart a crashing service within seconds.</p><p>When necessary, panic without worry.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecbe6fa95785" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/i-actually-agree-with-this-ecbe6fa95785">I actually agree with this.</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Immutable Builders in Go, Using Value Receivers]]></title>
            <link>https://medium.com/the-go-journey/simple-immutable-builders-in-go-using-value-receivers-393cf4cdd61c?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/393cf4cdd61c</guid>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Fri, 11 Oct 2019 15:57:08 GMT</pubDate>
            <atom:updated>2019-10-11T15:56:43.298Z</atom:updated>
            <content:encoded><![CDATA[<p>Even in a simple language like Go, concurrently updating mutable state is like playing with fire. Take this piece of code, for example:</p><pre>l := content.NewLoader() <br>l.PageCount = 5 <br>c := l.Load(bytes)</pre><p>Can you be sure that what you are loading is actually going to contain five pages? What if another goroutine having access to l, interjects and sets PageCount to 1000? Or worse, updates the state of l such that a panic is inevitable?</p><p>The simplest solution to this is to pack as much of the initial state configuration into the initialisation step. Constructors do not exist in Go, but unless we speak about a data-only struct (no logic), I would always recommend providing an initialiZer func NewLoader(...) and keeping as much of the state of the struct unexported. This will transform the previous piece of code into:</p><pre>l := content.NewLoader(pageCount: 5) <br>c := l.Load(bytes)</pre><p>The problem there becomes apparent when you start having more than three arguments:</p><pre>l := content.NewLoader(pageCount: 5, offset: 3, protocol: &quot;HTTP&quot;, //... ) <br>c := l.Load(bytes)</pre><p>How can we initialize Loader in a safe way, providing for some defaults, and without having to pack tens of parameters into the initializing func? There are various ways to achieve this. I have already written about <a href="https://preslav.me/2019/07/07/implementing-a-functional-style-builder-in-go/">one way</a> to approach this, another could be the functional options approach, suggested by <a href="https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis">Dave Cheney</a>.</p><p>The simplest one I have found so far, takes advantage of an innate property of the Go language. Namely, the fact that everything is passed by value. One of the first questions many go beginners ask about, is the difference between <a href="https://tour.golang.org/methods/8">value and pointer receivers</a>. Pointer receivers are usually the preferred way to go, often, as an (premature) optimization, rather than because modifications are required. A bit underrated, value receivers have one big advantage, which is that they are safe for concurrent use. What a value receiver would get is a copy of the original value. This makes them perfect for implementing builder methods:</p><pre>type Loader struct {<br>	pageSize int<br>}<br><br>func NewLoader() *Loader {<br>	return &amp;Loader{<br>		pageSize:10, // default<br>	}<br>}<br><br>// check the use of a value receiver here<br>func (l Loader) WithPageSize(ps int) *Loader {<br>	l.pageSize = ps<br>	return &amp;l<br>}<br><br>// The rest could be your usual pointer receivers<br>func (l *Loader) Load(bytes []byte) string {<br>	// ...<br>}</pre><p>The fact that we use a value receiver will cause the value of l to be copied, so technically, what we set pageSize to is a completely different place in memory. This is why we have to return a pointer to it and and reassign l:</p><pre>l := content.NewLoader().<br>         withPageSize(5)<br><br>c := l.Load(bytes)</pre><p>This will cause some copying and a bit of work for the garbage collector, but in the grand scheme of things, it will be a negligible overhead. The safety that you gain is far more important.</p><p>Let me know what you think.</p><p><em>Originally published at </em><a href="https://preslav.me/2019/10/06/simple-immutable-builders-in-go-using-value-receivers/"><em>https://preslav.me</em></a><em> on October 6, 2019. My blog runs on your generous </em><a href="https://www.buymeacoffee.com/0B7zhlQ2I"><em>☕️ donations</em></a><em>. If you like my writing, you’re very welcome to drop by and </em><a href="https://www.buymeacoffee.com/0B7zhlQ2I"><em>buy me a coffee</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=393cf4cdd61c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/simple-immutable-builders-in-go-using-value-receivers-393cf4cdd61c">Simple Immutable Builders in Go, Using Value Receivers</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[X509: Certificate Signed by Unknown Authority (Running a Go App Inside a Docker Container)]]></title>
            <link>https://medium.com/the-go-journey/x509-certificate-signed-by-unknown-authority-running-a-go-app-inside-a-docker-container-a12869337eb?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/a12869337eb</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Fri, 16 Aug 2019 14:14:59 GMT</pubDate>
            <atom:updated>2021-01-08T11:06:53.023Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This story is available free of charge at </em><a href="https://preslav.me/2019/08/11/x509-certificate-signed-by-unknown-authority-running-a-go-app-inside-a-docker-container/"><em>https://preslav.me</em></a><em>.</em></p><p>If you ever get the following message:</p><pre>x509: certificate signed by unknown authority</pre><p>While running your Go app in a Docker container, there is a chance that you might not have the necessary trusted certificates installed in your Docker container. Assuming that you run your Go apps in lightweight containers, based on <a href="https://docs.docker.com/develop/develop-images/baseimages/#create-a-simple-parent-image-using-scratch">Scratch</a> or Alpine, you will have to add the certificates yourselves.</p><p>On Alpine, this can be done using the default package installer:</p><pre>RUN apk --no-cache add ca-certificates</pre><p>Since Scratch is not based on a particular distribution you would have to download the certificates manually and add them as part of the build process:</p><pre>ADD ca-certificates.crt /etc/ssl/certs/</pre><h3>Further Reading</h3><ul><li><a href="https://stackoverflow.com/questions/52969195/docker-container-running-golang-http-client-getting-error-certificate-signed-by">Docker container running golang http.Client getting error `certificate signed by unknown authority`</a></li><li><a href="https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324">Create the smallest and secured golang docker image based on scratch</a></li></ul><p>I am a software engineer at KI labs GmbH and advocate for strong developer culture. In my free time, I enjoy running in the woods, reading a great book, or working on my next piece of writing/music.</p><p><a href="https://www.buymeacoffee.com/0B7zhlQ2I">Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a12869337eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/x509-certificate-signed-by-unknown-authority-running-a-go-app-inside-a-docker-container-a12869337eb">X509: Certificate Signed by Unknown Authority (Running a Go App Inside a Docker Container)</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Reasons to Consider Go Coming from Java]]></title>
            <link>https://medium.com/the-go-journey/my-reasons-to-consider-go-coming-from-java-b8f436e59c38?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/b8f436e59c38</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[articles]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Mon, 15 Jul 2019 06:07:52 GMT</pubDate>
            <atom:updated>2019-05-08T09:09:58.125Z</atom:updated>
            <content:encoded><![CDATA[<p>I hate listicles, and I am highly hoping that this doesn’t become one of them. Yet, I somehow felt the need to write down the reasons why I am giving Go a second (or maybe, third 🤔) chance. To the Java developers out there, searching for a new weapon of choice, I am hoping that this will give you a bit of perspective. This is not a description of Go-specific features. For those, readers can find plenty of information online.</p><p>The first time I saw a relatively simple Go program, my internal reaction was “Why all the torture?”. Somehow, things I used to solve with a Python or even a Java one-liner, look ginormously over-bloated in Go. At least, on the surface. Searching for an answer, I found this talk by Rob Pike, which helped put things in some order:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrFejpH_tAHM%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrFejpH_tAHM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrFejpH_tAHM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef8d6522f9a728aa2f08f12a15166f21/href">https://medium.com/media/ef8d6522f9a728aa2f08f12a15166f21/href</a></iframe><p>The thing is, unlike other languages, Go has been left out of many “niceties” of modern programming, and this was an intentional decision. More features add a level of cognitive burden. Of course, they also add more productivity, but at the cost of a higher comprehension barrier. I remember the days before Java 8, and how excited I was to see lambdas and streams make it into the language. A lot of previously lengthy boilerplate code was about to get replaced by a more elegant and fluent approach. Suddenly, every problem I ran into, I tried to solve using those two alone. So much so, that I often ended up spending hours screwing the logic of my code, because suddenly, no other approach seemed elegant enough. And I was not alone in this — the rest of my team was doing it too. Not long after, some pieces of the code turned into crystal figures — beautiful at first sight, but very brittle and difficult to move around.</p><p>Some programming languages focus on developer satisfaction when writing, but miss on the long-term maintainability of the piece of software. Others, like Go, sacrifice the expressiveness, in favor of readability and easy comprehension. I tend to over-engineer things (I believe you too, fellow Java engineers), so for me writing Go code feels a bit like therapy. By offering less, it teaches me to focus on getting the right things done, instead of getting stuck in the design phase, trying to make things “right”.</p><p>Don’t trust much of what you read about Go online. It is a tough nut to crack. Be prepared for a change in how you write code, especially, if you switch from a more fluent language like Scala or Kotlin. If you are a fan of immutability as part of the language, you’re up for a change of thinking. As said before, nothing is impossible, it just takes time. Give it time and come back after a while. In my short history with Go, there have been some upsides, followed by a period of recapitulation, eventual comeback, and understanding why things are the way they are.</p><p>Remember:</p><blockquote><em>Verbosity is a feature. Simplicity is complicated</em></blockquote><p>Despite being called an 80s language living in the 21st century, Go’s ecosystem has borrowed from many of the trends and best practices in software development nowadays. The setup process is nice and easy and brings in a myriad of tiny tools and utils that all fit in place right away. Formatting, package management, linting, module management (as of recent versions) are all things that one does not have to really think about. Those are really taken care of with the standard tooling.</p><p>Besides that, the Go standard library is one of the most complete Stdlibs I’ve worked with so far, and understandably so. Go came out relatively recently, so a lot of the standards and practices in software had a chance to make it in the library right from the beginning, rather than get added years after. As a result, the Go standard library feels like something that a developer can actually use in their daily work, rather than something that always needs to get wrapped inside a third-party library.</p><p>That said, I don’t share the opinion of Go purists to use the standard library only. There should be a balance, and although I am not a fan of <em>“npm install”</em>-ing everything, standard libraries are created to be building blocks, so don’t feel ashamed if you have to pull in some libraries to ease your work. There are some pretty <a href="https://github.com/avelino/awesome-go">good ones</a> out there.</p><p>We have all heard that, but the actual outcome blew my mind away!</p><p>I have spent the bulk of the past decade working with Spring, and it has gradually become my go-to solution for all things Web. Despite working with Flask on my current projects, Spring (Boot) will always remain near and dear to my heart.</p><p>Yet, Spring is a beast. You might not notice it, because the hardware has gotten quite cheap these days, but a lot of otherwise useful resources get locked up when running a hefty JVM app.</p><p>To see where Go stands on this, I rebuilt a not-so-smallish Spring Boot app of mine using Go. I did not even take the purist approach but was quite liberal in my choice of libraries. The results blew all of my previous expectations by a factor of ten. The Spring app took nearly half a GB right away, keeping around 5–10% of my MacBook Pro’s CPU busy at all time (spiking when requests came in). For deploying a single artefact, I had built a fat JAR, which is quite a standard procedure for developing Java apps these days. It took a couple of hundred of MBs as well. Due to the JVM warmup and Spring’s loading all dependencies, it took almost a minute until the app was ready.</p><p>For comparison, the Go app ran instantaneously (let’s be fair, there was literally no component scanning and reflection involved). Even at the height of handling requests, the CPU barely reached 1% (mostly sitting around 0.1%). With all libraries and assets included, the final binary ended up being around 20MB. The RAM usage, however, I found to be a metric that changed everything. In an age where a typical messaging application might eat up to a couple of GBs, this app was sitting there minding its business, rocking a 20MB?!? footprint. 20MB? Even if following a very naive logic, this is close to fitting 20 of these apps together, for the cost of running one Spring Boot app!</p><p>Before the expert readers start criticizing, yes, none of this is really a fair comparison. The fact that an app is built in Go does not guarantee a blazing fast performance if there is a lot of runtime loading and checks. Also, experts can tweak a JVM app in various ways, significantly reducing the footprint of the app. It takes time and effort, but it is certainly doable. And of course, there is always the argument about cheap hardware and premature optimization.</p><p>I am not saying that this should necessarily resonate with you, but it certainly does with me. I strive to be a minimalist. Exactly because the hardware is so cheap these days, I believe that people and companies spend way more on it than they probably should. There are various articles out there speculating about the millions and hundreds of millions of dollars that big software companies pay for server costs every year. All of it to pay for servers that get powered by electricity generated from burning fossil fuels.</p><p>The Go community is welcoming and very helpful. Part of the helpfulness factor comes from the fact that many gophers have already spent years programming in a different domain. What makes these people stick around and help each other, is the experience of the past, having taught them that complexity does not equal productivity.</p><p>As people say in stock trading, “always do your own research”. I don’t want to convince you to switch and use Go full-time, because I haven’t convinced myself yet. As with everything else, programming languages are just tools, and there will always be a different tool which is better for the particular circumstances. What I hope to have managed to convince you, is to try to understand where the need for the language came from and what it tries to solve</p><p>As always, happy coding!</p><p><em>Originally published at </em><a href="https://preslav.me/2019/05/07/my-reasons-to-consider-go-coming-from-java/"><em>https://preslav.me</em></a><em> on May 7, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8f436e59c38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/my-reasons-to-consider-go-coming-from-java-b8f436e59c38">My Reasons to Consider Go Coming from Java</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Version Information to Go Binaries]]></title>
            <link>https://medium.com/the-go-journey/adding-version-information-to-go-binaries-e1b79878f6f2?source=rss----74bea50445ff---4</link>
            <guid isPermaLink="false">https://medium.com/p/e1b79878f6f2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Preslav Rachev]]></dc:creator>
            <pubDate>Mon, 15 Jul 2019 05:33:42 GMT</pubDate>
            <atom:updated>2019-07-09T19:41:56.472Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the things that I find really neat about Go, is the single-executable delivery model. For small projects, it’s as simple as dragging and dropping the built executable right where I need it. After some time, however, I might easily forget which version of my codebase a given executable has been built upon. If I have to revert a change, how can I make sure that I build from the right commit?</p><p>In large projects, this is where CI/CD comes to save the day. For small prototypes, however, setting up CI might be an unnecessary overkill until a much later stage in the process.</p><p>Luckily, there is an easy way to “bake” the information about the current commit hash right into the built executable.</p><p>Go does not have a dedicated build system, but the standard practice across the community is to use <a href="https://en.wikipedia.org/wiki/Make_(software)">make</a>. Make is widely available across *nix operating systems (incl. macOS), so I would usually add a simple Makefile to most of my Go projects. In this case, my makefile would look like this:</p><pre>GOOS=linux<br>GOARCH=386<br><br>.PHONY: build<br><br>GIT_COMMIT := $(shell git rev-list -1 HEAD)<br><br>build:<br>	GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags &quot;-X main.gitCommit=$(GIT_COMMIT)&quot; .</pre><p>Two things to note here:</p><ol><li>GIT_COMMIT will store of the value of the current commit hash that our code base is at.</li><li>-ldflags &quot;-X main.gitCommit=$(GIT_COMMIT)&quot; is Go&#39;s way of telling the linker to pass the commit hash to a variable in the code (main.gitCommit). Think of this as &quot;baking&quot; the information right into the compiled executable.</li></ol><p>All we need to make this happen, is use make build instead of go build ...</p><p>In our code, we can check for the presence of a flag (e.g. -v) and display the hash:</p><pre>package main<br><br>var gitCommit string<br><br>func printVersion() {<br>	log.Printf(&quot;Current build version: %s&quot;, gitCommit)<br>}<br><br>func main() {<br>	versionFlag := flag.Bool(&quot;v&quot;, false, &quot;Print the current version and exit&quot;)<br>	flag.Parse()<br><br>	switch {<br>	case *versionFlag:<br>		printVersion()<br>		return<br>	}<br>	// continue with other stuff<br>}</pre><p>Related reading:</p><ul><li><a href="https://en.wikipedia.org/wiki/Make_%28software%29">Make (software) - Wikipedia</a></li><li><a href="https://blog.alexellis.io/inject-build-time-vars-golang/">Inject build-time variables with Golang</a></li><li><a href="https://goreleaser.com/">GoReleaser</a></li></ul><p><em>Originally published at </em><a href="https://preslav.me/2019/07/09/adding-version-information-to-go-binaries/"><em>https://preslav.me</em></a><em> on July 9, 2019.</em></p><p><a href="https://www.buymeacoffee.com/0B7zhlQ2I">Buy me a coffee</a> ☕️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1b79878f6f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-go-journey/adding-version-information-to-go-binaries-e1b79878f6f2">Adding Version Information to Go Binaries</a> was originally published in <a href="https://medium.com/the-go-journey">The Go Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>