<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Henryk Konsek</title>
    <description>The latest articles on DEV Community by Henryk Konsek (@hekonsek).</description>
    <link>https://dev.to/hekonsek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F566940%2Fb2901c7b-54b5-44d4-b9ba-fc2563da77b6.jpg</url>
      <title>DEV Community: Henryk Konsek</title>
      <link>https://dev.to/hekonsek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hekonsek"/>
    <language>en</language>
    <item>
      <title>Quickstart: Java command line tool</title>
      <dc:creator>Henryk Konsek</dc:creator>
      <pubDate>Mon, 21 Mar 2022 15:50:10 +0000</pubDate>
      <link>https://dev.to/hekonsek/quickstart-java-command-line-tool-20cc</link>
      <guid>https://dev.to/hekonsek/quickstart-java-command-line-tool-20cc</guid>
      <description>&lt;p&gt;I keep forgetting how to create new projects from scratch, so I like to keep my personal set of &lt;a href="https://github.com/hekonsek?tab=repositories&amp;amp;q=quickstart-&amp;amp;type=&amp;amp;language=&amp;amp;sort="&gt;quickstarts&lt;/a&gt; on GitHub. &lt;a href="https://github.com/hekonsek/quickstart-java-cli"&gt;Quickstart for Java command line tool&lt;/a&gt; is a simple implementation of &lt;a href="https://en.wikipedia.org/wiki/Grep"&gt;Grep command&lt;/a&gt; implemented as Java fat jar.&lt;/p&gt;

&lt;p&gt;Project is pretty feature-complete right now, however here is the short list of the things I'd like to improve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add support for command line parsing&lt;/li&gt;
&lt;li&gt;explicitly manage version numbers of all Maven plugins used by the project (compiler plugin, clean plugin, site plugin, etc)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>linux</category>
    </item>
    <item>
      <title>Using context in Go - timeout</title>
      <dc:creator>Henryk Konsek</dc:creator>
      <pubDate>Thu, 18 Feb 2021 11:07:19 +0000</pubDate>
      <link>https://dev.to/hekonsek/using-context-in-go-timeout-hg7</link>
      <guid>https://dev.to/hekonsek/using-context-in-go-timeout-hg7</guid>
      <description>&lt;p&gt;Go comes with a powerful concurrency control tool called &lt;a href="https://golang.org/pkg/context"&gt;context&lt;/a&gt;. Context is primarily used when client should be able to keep a control over an execution of the library code.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Timeout control with context
&lt;/h1&gt;

&lt;p&gt;One of the most common example of such pattern is controlling timeout of the function we are calling from our code. This is primarily useful when dealing with IO and network calls which can be blocking and unreliable by their nature.&lt;/p&gt;

&lt;p&gt;Let's consider this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;callSlowApi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;// this is slow API call&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;callSlowApi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We call some slow REST API here. Right now we cannot control the execution of the &lt;code&gt;callSlowApi()&lt;/code&gt; function. In particular even if we know that API is flaky and response can take ages, we cannot control for how long our client code is ready to wait before we want to cancel our attempt to call the API.&lt;/p&gt;

&lt;p&gt;Good library design in Go should include &lt;code&gt;context.Context&lt;/code&gt; as a first parameter in the function to allow client to control the timeout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;callSlowApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;// this is slow API call, but context aware&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// If API call takes longer than 5 seconds, return context timeout error&lt;/span&gt;
&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;callSlowApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now execution of &lt;code&gt;callSlowApi&lt;/code&gt; function can be controlled from the client code! In the example above our client code specified that we are ready to wait 5 seconds tops before we give up on the API call.&lt;/p&gt;

&lt;p&gt;Keep in mind that we call &lt;code&gt;defer cancel()&lt;/code&gt; in our example. It is used to send a signal to the &lt;code&gt;callSlowApi&lt;/code&gt; function that we are not interested in this particular call anymore and it should be canceled. It is a good practice to call cancel function after we used a context in a call to avoid context leaks.&lt;/p&gt;

&lt;h1&gt;
  
  
  More examples
&lt;/h1&gt;

&lt;p&gt;In &lt;a href="https://github.com/hekonsek/quickstart-go-context/blob/main/main.go"&gt;this example&lt;/a&gt; you can see context timeout in action.&lt;/p&gt;

&lt;p&gt;We define a "mock" task function emulating long running process that could time out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;runTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taskTime&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;After&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskTime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finished long running task."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Timed out context before task is finished."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we're passing context as the first argument to it. Thanks to this approach we can control the timeout behavior on the level of the client code calling the function. In the example below we are calling our mock task for 3 seconds and with 1 second context timeout. As a result we should see function being timed out and canceled after one second:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;timeoutContextBeforeTaskIsFinished&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"This example should time out task execution:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Always cancel() to avoid context leak&lt;/span&gt;

    &lt;span class="n"&gt;runTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="n"&gt;execution&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;Timed&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;finished&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example below we are calling our mock task for 1 second and with 3 second context timeout. As a result we should see function being completed without a timeout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;finishTaskBeforeContextTimeout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"This example should finish task execution before context timeout:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Always cancel() to avoid context leak&lt;/span&gt;

    &lt;span class="n"&gt;runTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;finish&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="n"&gt;execution&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;Finished&lt;/span&gt; &lt;span class="n"&gt;long&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;Go &lt;code&gt;context&lt;/code&gt; is a powerful package that allows you to design library API with a powerful concurrency and reliability controls in place. It is highly recommended to include &lt;code&gt;context.Context&lt;/code&gt; as a first parameter to the CPU/IO/network intensive functions you author. That would enable clients using your code to control how it behaves in case of reliability issues.&lt;/p&gt;

&lt;p&gt;Context timeout is a great way to control how your client code interacts with an unreliable IO and networks.&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>Installing Windows 10 Terminal</title>
      <dc:creator>Henryk Konsek</dc:creator>
      <pubDate>Fri, 12 Feb 2021 16:19:43 +0000</pubDate>
      <link>https://dev.to/hekonsek/installing-windows-10-terminal-3dod</link>
      <guid>https://dev.to/hekonsek/installing-windows-10-terminal-3dod</guid>
      <description>&lt;p&gt;If you are Linux or MacOS user, then for sure you are used to feature-rich terminals. And probably you cringe a little bit inside every time you have to use Windows command prompt. I feel you, but maybe you don't know yet that Windows 10 offers official (and free) next generation &lt;a href="https://docs.microsoft.com/en-us/windows/terminal"&gt;terminal for Windows&lt;/a&gt;. Terminal for Windows borrows all the best features from Linux/Unix terminals. &lt;/p&gt;

&lt;p&gt;You can try it really easily! Terminal is available in Windows Store, just find the application in the Store:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xGmqNFl9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/httyt6bzg78434dhnpzj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xGmqNFl9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/httyt6bzg78434dhnpzj.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installation you should see it as a new application in your run menu:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9bwMELM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ctmr9hcspz00gvpirkop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9bwMELM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ctmr9hcspz00gvpirkop.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Probably the most important Terminal's feature is a support for multiple tabs. You can open new tab by clicking plus sign at the top of the Terminal window. Or even better, you can click the expand button to choose the terminal type you would like to open in new tab (PowerShell, Command Prompt, Linux distribution like Ubuntu, etc).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZOvnBQ2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/aw64ktze8ek0m4ag8o1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZOvnBQ2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/aw64ktze8ek0m4ag8o1t.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Microsoft did really great job when it comes to Terminal and they keep adding new awesome stuff with every release. Go give it a try!&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>windows</category>
    </item>
    <item>
      <title>Go interview task example -  REST API</title>
      <dc:creator>Henryk Konsek</dc:creator>
      <pubDate>Fri, 12 Feb 2021 10:16:34 +0000</pubDate>
      <link>https://dev.to/hekonsek/go-interview-task-example-rest-api-54ld</link>
      <guid>https://dev.to/hekonsek/go-interview-task-example-rest-api-54ld</guid>
      <description>&lt;p&gt;Here is a sample application specification I use as a base for Go interviews. It's pretty simple to write and I use it as a foundation for further conversations with a candidate.&lt;/p&gt;

&lt;h1&gt;
  
  
  Task specification
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;create simple Go application exposing REST API&lt;/li&gt;
&lt;li&gt;no specific web framework is required to be used&lt;/li&gt;
&lt;li&gt;when &lt;code&gt;/api/weather&lt;/code&gt; endpoint is called, fetch weather alerts data for the state of New York using &lt;a href="https://api.weather.gov/alerts/active?area=NY"&gt;this API&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;read weather alerts headlines from the &lt;code&gt;api.weather.gov&lt;/code&gt; API response (JsonPath &lt;code&gt;$.features[*].headline&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;return alerts headlines in a similar response:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"alerts": ["Wind Chill Advisory issued February 12 at 4:02AM EST until February 12 at 10:00AM EST by NWS Binghamton NY"]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Extra points
&lt;/h1&gt;

&lt;p&gt;It is up to you how simple or complex the application will be. However you can treat this application as an occasion to brag about the things you know. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do you like unit testing? Go for it and show us your favorite testing libraries in action!&lt;/li&gt;
&lt;li&gt;Docker fan? Dockerize the application then and include your Dockerfile!&lt;/li&gt;
&lt;li&gt;Any other cool libraries you know and wanna show us? Let us learn from you! &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>recruiting</category>
    </item>
    <item>
      <title>What is the right AWS Kubernetes distribution for you?</title>
      <dc:creator>Henryk Konsek</dc:creator>
      <pubDate>Wed, 10 Feb 2021 15:34:38 +0000</pubDate>
      <link>https://dev.to/hekonsek/what-is-the-right-aws-kubernetes-distribution-for-you-2173</link>
      <guid>https://dev.to/hekonsek/what-is-the-right-aws-kubernetes-distribution-for-you-2173</guid>
      <description>&lt;p&gt;Considering cloud market share held by Amazon, it is very likely that the cloud of your choice is AWS. If that is the case and you have already decided that Kubernetes is the way to schedule your workloads, you are probably asking yourself what cluster hosting approach should you choose. While choosing AWS EKS - the AWS managed Kubernetes offering could be the first thing that comes to your mind - it is worth to know the alternatives and make an educated decision.  &lt;/p&gt;

&lt;h1&gt;
  
  
  The most popular Kubernetes cluster hosting methods for AWS
&lt;/h1&gt;

&lt;p&gt;There are a myriad of different ways to run your Kubernetes cluster in AWS. Let's discuss some of the most popular ones.&lt;/p&gt;

&lt;p&gt;Currently the most popular cluster hosting methods for AWS are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kubernetes The Hard Way&lt;/li&gt;
&lt;li&gt;Kubeadm&lt;/li&gt;
&lt;li&gt;KubeSpray&lt;/li&gt;
&lt;li&gt;Kops&lt;/li&gt;
&lt;li&gt;EKS&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Kubernetes The Hard Way
&lt;/h2&gt;

&lt;p&gt;Hosting Kubernetes cluster "&lt;em&gt;the hard way&lt;/em&gt;" means that the cluster has been bootstrapped by following steps from the famous &lt;a href="https://github.com/kelseyhightower/kubernetes-the-hard-way"&gt;Kubernetes The Hard Way&lt;/a&gt; guide authored by &lt;a href="https://twitter.com/kelseyhightower"&gt;Kelsey Hightower&lt;/a&gt;. &lt;em&gt;Kubernetes The Hard Way&lt;/em&gt; describes how to manually configure and install each Kubernetes component (like Kubernetes scheduler, Kubernetes API server, Containerd, CoreDNS, CNI and Etcd).&lt;/p&gt;

&lt;p&gt;In practice &lt;em&gt;The Hard Way&lt;/em&gt; approach requires you to start some EC2 Linux virtual machines (that will serve as your master and worker nodes) and installing each Kubernetes component (Etcd, Containerd, Kubernetes scheduler and so forth) into these Linux servers.&lt;/p&gt;

&lt;p&gt;While &lt;em&gt;Kubernetes The Hard Way&lt;/em&gt; is a great way learn a ton about Kubernetes internals, it is probably not the best choice for your production Kubernetes cluster. The main reason for that is because with &lt;em&gt;The Hard Way&lt;/em&gt; approach all the cluster administration burden is on you and your organization. Creating and configuring all the infrastructure required by &lt;em&gt;Kubernetes The Hard Way&lt;/em&gt; cluster is an extremely expensive activity, and I don't recommend following this approach if you don't plan to hire devOps engineers / SREs (Site Reliability Engineers) dedicated for this task.   &lt;/p&gt;

&lt;p&gt;The good case for &lt;em&gt;The Hard Way&lt;/em&gt; approach would be if you would like to run customized version of Kubernetes cluster where you have full control over an every component of your installation. And if you are not afraid to cover the cost associated with this approach. &lt;/p&gt;

&lt;h2&gt;
  
  
  Kubeadm
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/kubernetes/kubeadm"&gt;Kubeadm&lt;/a&gt; is a cluster provisioning tool implementing the best-practices for creating Kubernetes clusters (following &lt;em&gt;Kubernetes The Hard Way&lt;/em&gt; steps). Kubeadm performs the actions necessary to get a minimum viable and secure cluster. It follows Kubernetes operator architectural approach for cluster creation and management. What is also important, Kubeadm is &lt;a href="https://github.com/kubernetes/community/tree/master/sig-cluster-lifecycle#kubeadm"&gt;an official Kubernetes SIG Lifecycle project&lt;/a&gt; - this is important because official Kubernetes SIG projects usually tent to have better community support and be more mature than their non-official counterparts.&lt;/p&gt;

&lt;p&gt;Kubeadm is a great choice if you are ready to deal with the same con as in case of &lt;em&gt;The Hard Way&lt;/em&gt; approach (i.e. provisioning EC2 servers and handling a cluster administration burden by yourself), but you would like to make provisioning of the cluster itself easier and automated out-of-the-box. Kubeadm makes it also easier to perform common cluster maintenance practices, such as a cluster version upgrade process or adding additional worker node to a cluster.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Kubespray
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/kubernetes-sigs/kubespray"&gt;Kubespray&lt;/a&gt; is a set of &lt;a href="https://www.ansible.com/"&gt;Ansible&lt;/a&gt; resources (playbooks, inventories, etc) focused on Kubernetes provisioning, configuration and management. Kubespray can deploy to almost any kind of target environment you might want (including AWS, GCE, Azure, OpenStack, vSphere, Packet, Oracle Cloud Infrastructure) or even to bare metal (with an array of supported Linux distributions).&lt;/p&gt;

&lt;p&gt;Kubespray is also&lt;a href="https://github.com/kubernetes/community/tree/master/sig-cluster-lifecycle#kubespray"&gt;an official Kubernetes SIG Lifecycle project&lt;/a&gt; - as in case of Kubeadm, this is important because official Kubernetes SIG projects have great community support. What is very interesting, starting from version 2.3&lt;br&gt;
Kubespray supports kubeadm-based deployments. Moreover, starting since version 2.8 Kubespray deprecated non-Kubeadm deployments. It means that currently Kubespray basically relies on Kubeadm to perform cluster creation under the hood. &lt;/p&gt;

&lt;p&gt;Kubespray is a strong candidate if you don't want to use EKS for some reasons (for example you need more customized Kubernetes installation over regular EC2 instances), but at the same time you need some higher level opinionated approach for a cluster provisioning process and configuration. Kubespray is also a great choice if you need a cloud-agnostic way of cluster provisioning and management - Kubespray allows you to provision your AWS cluster in a bare metal mode over pre-provisioned EC2 instances accessible via SSH. Another important factor for Kubespray would be familiarity with Ansible, if your operation folks already know Ansible - they will feel at home. &lt;/p&gt;

&lt;h2&gt;
  
  
  Kops
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/kubernetes/kops"&gt;Kops&lt;/a&gt; is described as &lt;em&gt;"kubectl for clusters"&lt;/em&gt; . Kops is a toolkit which brings you&lt;br&gt;
very opinionated way of managing clusters on supported cloud providers (including AWS and GCP). Kops is not based on Ansible like Kubespray, instead it relies on AWS API calls directly. Kops provisions not only the cluster itself, but also an EC2-based infrastructure for your cluster. Kops leverages cloud specific features of each cloud provider to brings you the best experience - for example in AWS it will create auto scaling and self healing EC2 autoscaling group to host your cluster nodes. Kubespray is also &lt;a href="https://kops.sigs.k8s.io/"&gt;an official Kubernetes SIG Lifecycle project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When to use Kops? If you don't want to use EKS for some reasons (like fine-tuning cluster configuration), but you would prefer to rely on higher level and very opinionated tool providing rock solid and battle tested cluster setup - Kops is a way to go. This is also a good option if you don't care so much about being cloud-agnostic.&lt;/p&gt;

&lt;h2&gt;
  
  
  EKS
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/eks"&gt;AWS EKS&lt;/a&gt; is a managed Kubernetes offering from AWS. It gives you highly available managed Kubernetes control plane, and a couple of ways to connect node workers to it (including on demand EC2 instances, Spot instances or even serverless compute engine Fargate). Cluster itself costs about 72 USD per month. In general EKS is the easiest way of provisioning and operating Kubernetes clusters in AWS. I highly recommend you choosing EKS if there is really no good reason for doing otherwise.&lt;/p&gt;

&lt;p&gt;What could be reason for not using EKS? One scenario would be customization of your Kubernetes installation. EKS provides&lt;br&gt;
you opinionated setup where you cannot tune every possible piece of your installation. Or even if certain customization is possible, you might lose AWS support for it. For example Amazon only officially supports the Amazon VPC CNI plugin.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;AWS EKS is in general a reasonable default for running Kubernetes clusters in the AWS environment. If for some reason you don't want or can't use EKS, you can try to use less opinionated and more configurable alternatives. Keep in mind however that the more configurable and less opinionated approach is, the more expertise and operational resources is required in-house for your organization to successfully operate it. &lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>aws</category>
      <category>cloud</category>
      <category>sre</category>
    </item>
    <item>
      <title>25 interview questions for Go Developer position</title>
      <dc:creator>Henryk Konsek</dc:creator>
      <pubDate>Tue, 09 Feb 2021 11:30:22 +0000</pubDate>
      <link>https://dev.to/hekonsek/20-interview-questions-for-go-developer-position-41ce</link>
      <guid>https://dev.to/hekonsek/20-interview-questions-for-go-developer-position-41ce</guid>
      <description>&lt;p&gt;This is a list of common questions that can be asked by technical interviewers for Go developer position. This is definitely not a complete list, just a subset I find pretty likely to occur during the interview.&lt;/p&gt;

&lt;h1&gt;
  
  
  Questions
&lt;/h1&gt;

&lt;p&gt;The questions are grouped by the category. Again - the list of categories is far from being complete, however it is very likely that question from given category will be asked during the interview.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modules
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What are Go modules?&lt;/li&gt;
&lt;li&gt;What was used before Go modules were introduced?&lt;/li&gt;
&lt;li&gt;What is vendoring?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interfaces
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is an interface in Go?&lt;/li&gt;
&lt;li&gt;How many functions can be usually found in an average Go stdlib interface?&lt;/li&gt;
&lt;li&gt;How to define a function argument that can be anything?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pointers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to indicate nil string as a return type?&lt;/li&gt;
&lt;li&gt;How to modify arguments passed to a function?&lt;/li&gt;
&lt;li&gt;When arguments passed to a function is stored the stack? When on the heap? What is a difference?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Slices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to define a variadic function?&lt;/li&gt;
&lt;li&gt;How to pass a slice into a variadic function?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Strings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to get a substring?&lt;/li&gt;
&lt;li&gt;How to split a string?&lt;/li&gt;
&lt;li&gt;How to join a slice of strings?&lt;/li&gt;
&lt;li&gt;How to check if a string starts with a substring?&lt;/li&gt;
&lt;li&gt;How to check if a string ends with a substring?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is context? Why is it useful?&lt;/li&gt;
&lt;li&gt;How to define a context timeout for function execution?&lt;/li&gt;
&lt;li&gt;How to handle a context timeout within that function?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Concurrency
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Improve the following library function:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;func ExecuteShellCommand(cmd string) (output []string)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Allow function caller to asynchronously receive every line of stdout of executed shell command (in real time)&lt;/li&gt;
&lt;li&gt;Notify function caller that command execution is over&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  IO
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to read local file as slice of bytes?&lt;/li&gt;
&lt;li&gt;How to convert &lt;code&gt;io.Reader&lt;/code&gt; into slice of bytes? &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  JSON support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What library and function would you use to parse JSON file?&lt;/li&gt;
&lt;li&gt;What library and function would you use to parse JSON file that doesn't fit into RAM?&lt;/li&gt;
&lt;li&gt;What JSON library would you recommend from the usability point of view? For example to support nested queries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;What do you think about the list above? What would you add or remove? What other questions do you find to be asked frequently during interviews? What questions to you like to ask when interviewing your candidates? Please leave the answer in the comments!&lt;/p&gt;

</description>
      <category>go</category>
      <category>recruiting</category>
    </item>
  </channel>
</rss>
