<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Go Basics Training – Exercises</title><link>/docs/exercises/</link><description>Recent content in Exercises on Go Basics Training</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="/docs/exercises/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: ASCII Pyramid</title><link>/docs/exercises/lab_ascii_pyramid/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/exercises/lab_ascii_pyramid/</guid><description>
&lt;h2 id="task">Task&lt;/h2>
&lt;p>Create a function which prints an ASCII Pyramid. The function must take the height of the pyramid as parameter.&lt;/p>
&lt;p>If you call the function with &lt;code>5&lt;/code> as parameter we should get the following pyramid:&lt;/p>
&lt;pre tabindex="0">&lt;code> *
***
*****
*******
*********
&lt;/code>&lt;/pre>&lt;h2 id="tips">Tips&lt;/h2>
&lt;details >
&lt;summary>Standard library packages&lt;/summary>
&lt;p>The package &lt;a href="https://pkg.go.dev/fmt" target="_blank" rel="noopener" class="godoc">fmt&lt;/a>
contains various print functions.&lt;/p>
&lt;/details>
&lt;details >
&lt;summary>Standard library functions&lt;/summary>
&lt;p>With &lt;a href="https://pkg.go.dev/fmt#Print" target="_blank" rel="noopener" class="godoc">fmt.Print&lt;/a>
you can print strings:&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">// print space
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000">fmt&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Print&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#34; &amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">// print newline
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000">fmt&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Print&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;\n&amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;details >
&lt;summary>Calculate number of spaces and stars&lt;/summary>
&lt;p>On each line you have to print the appropriate number of spaces and stars:&lt;/p>
&lt;ul>
&lt;li>spaces: &lt;code>height - lineNumber&lt;/code>&lt;/li>
&lt;li>stars: &lt;code>lineNumber * 2 - 1&lt;/code>&lt;/li>
&lt;/ul>
&lt;/details>
&lt;h2 id="solution">Solution&lt;/h2>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/blob/master/ascii-pyramid/main.go" target="_blank" rel="noopener" >https://github.com/acend/go-basics-training-examples/blob/master/ascii-pyramid/main.go&lt;/a>
&lt;/p></description></item><item><title>Docs: Number Guessing Game</title><link>/docs/exercises/lab_number_guessing_game/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/exercises/lab_number_guessing_game/</guid><description>
&lt;h2 id="task">Task&lt;/h2>
&lt;p>Write a number guessing game. At the start create a random number.
Then ask the user to enter a number on the command line (standard input) until the user guesses the correct number.&lt;/p>
&lt;p>If the user enters the string &lt;code>exit&lt;/code> the program should exit.&lt;/p>
&lt;p>The output could look like in the following example. In the example the user enters the numbers 5, 7 and 6.&lt;/p>
&lt;pre tabindex="0">&lt;code>guess number between 0 and 9
guess number: 5
wrong number. try again.
guess number: 7
wrong number. try again.
guess number: 6
correct
&lt;/code>&lt;/pre>&lt;h2 id="tips">Tips&lt;/h2>
&lt;details >
&lt;summary>Read line&lt;/summary>
&lt;p>With the &lt;a href="https://pkg.go.dev/bufio" target="_blank" rel="noopener" class="godoc">bufio&lt;/a>
package we can read from the standard input (&lt;a href="https://pkg.go.dev/os#Stdin" target="_blank" rel="noopener" class="godoc">os.Stdin&lt;/a>
) until a certain character occurs:&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">line&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">bufio&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">NewReader&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">os&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Stdin&lt;/span>&lt;span style="color:#000;font-weight:bold">).&lt;/span>&lt;span style="color:#000">ReadString&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#39;\n&amp;#39;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>The &lt;a href="https://pkg.go.dev/strings" target="_blank" rel="noopener" class="godoc">strings&lt;/a>
package contains various functions to work with strings. For example &lt;a href="https://pkg.go.dev/strings#TrimSpace" target="_blank" rel="noopener" class="godoc">strings.TrimSpace&lt;/a>
to remove whithspace characters (spaces, newlines, etc.) from strings.&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">line&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#000">strings&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">TrimSpace&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">line&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;details >
&lt;summary>Random number&lt;/summary>
&lt;p>The function &lt;a href="https://pkg.go.dev/math/rand#Intn" target="_blank" rel="noopener" class="godoc">rand.Intn&lt;/a>
returns a random integer. Before we use one of the random functions we have to seed the random number generator, otherwise we would always get the same number. As seed we can use the current time as nano seconds provided by the &lt;a href="https://pkg.go.dev/time#Time.UnixNano" target="_blank" rel="noopener" class="godoc">time&lt;/a>
package.&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">rand&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Seed&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">time&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Now&lt;/span>&lt;span style="color:#000;font-weight:bold">().&lt;/span>&lt;span style="color:#000">UnixNano&lt;/span>&lt;span style="color:#000;font-weight:bold">())&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">// 0 &amp;lt;= randomNumber &amp;lt; 10
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000">randomNumber&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">rand&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Intn&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#0000cf;font-weight:bold">10&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;details >
&lt;summary>Convert string to int&lt;/summary>
&lt;p>The package &lt;a href="https://pkg.go.dev/strconv" target="_blank" rel="noopener" class="godoc">strconv&lt;/a>
implements conversions to and from string representations of basic data types like &lt;code>int&lt;/code> or &lt;code>float64&lt;/code>.&lt;/p>
&lt;p>With &lt;a href="https://pkg.go.dev/strconv#Atoi" target="_blank" rel="noopener" class="godoc">strconv.Atoi&lt;/a>
you can convert a string into a &lt;code>int&lt;/code>.&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">number&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">strconv&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Atoi&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;8&amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">!=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// handle failed conversion
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;h2 id="solution">Solution&lt;/h2>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/blob/master/number-guessing/main.go" target="_blank" rel="noopener" >https://github.com/acend/go-basics-training-examples/blob/master/number-guessing/main.go&lt;/a>
&lt;/p></description></item><item><title>Docs: Robot</title><link>/docs/exercises/lab_robot/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/exercises/lab_robot/</guid><description>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>Imagine we have a robot which moves around on a coordinate system.
The robot starts at the position &lt;code>0,0&lt;/code>.&lt;/p>
&lt;p>For the robot we have a list of instructions in the following form:&lt;/p>
&lt;pre tabindex="0">&lt;code>right 3
up 1
left 5
right 4
down 2
up 2
&lt;/code>&lt;/pre>&lt;p>Each line is one instruction. An instruction consists of a direction and a number which describes how far we move into this direction. After each instruction the robot is in a new position.&lt;/p>
&lt;p>With the instructions from the example above we would do the following steps:&lt;/p>
&lt;ul>
&lt;li>The first instruction &lt;code>right 3&lt;/code> moves the robot to the position &lt;code>3,0&lt;/code>&lt;/li>
&lt;li>&lt;code>up 1&lt;/code> moves the robot to the position &lt;code>3,1&lt;/code>&lt;/li>
&lt;li>&lt;code>left 5&lt;/code> -&amp;gt; &lt;code>-2,1&lt;/code>&lt;/li>
&lt;li>&lt;code>right 4&lt;/code> -&amp;gt; &lt;code>2,1&lt;/code>&lt;/li>
&lt;li>&lt;code>down 2&lt;/code> -&amp;gt; &lt;code>2,-1&lt;/code>&lt;/li>
&lt;li>&lt;code>up 2&lt;/code> -&amp;gt; &lt;code>2,1&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>In the example above we visited 6 positions (&lt;code>3,0&lt;/code>, &lt;code>3,1&lt;/code>, &lt;code>-2,1&lt;/code>, &lt;code>2,1&lt;/code>, &lt;code>2,-1&lt;/code>, &lt;code>2,1&lt;/code>).
The furthest distance to the left we visited was &lt;code>-2&lt;/code>. The furthest distance to the right we visited was &lt;code>3&lt;/code>.&lt;/p>
&lt;h2 id="tasks">Tasks&lt;/h2>
&lt;p>Read all instructions from the file &lt;a href="./input.txt" >input.txt&lt;/a>
and perform the appropriate actions with the robot.&lt;/p>
&lt;p>Answer the following questions:&lt;/p>
&lt;ol>
&lt;li>What is the end position of the robot?&lt;/li>
&lt;li>Which is the distance furthest to the left, which the robot visited?&lt;/li>
&lt;li>Which is the distance furthest to the right, which the robot visited?&lt;/li>
&lt;li>Which position did we visit most often?&lt;/li>
&lt;/ol>
&lt;h2 id="tips">Tips&lt;/h2>
&lt;ul>
&lt;li>Try to solve the exercise only with the 6 example instructions first. Do not solve all tasks at once. Try to find the end position first and then try to extend your solution for the other tasks.&lt;/li>
&lt;/ul>
&lt;details >
&lt;summary>Read file line by line&lt;/summary>
&lt;ul>
&lt;li>
&lt;p>To read the file you can use &lt;a href="https://pkg.go.dev/os#ReadFile" target="_blank" rel="noopener" class="godoc">os.ReadFile&lt;/a>
which gives you the content of a whole file as a &lt;code>[]byte&lt;/code>.&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">rawData&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">os&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">ReadFile&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">fileName&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">!=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#000">err&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/li>
&lt;li>
&lt;p>You can iterate over each line by splitting the whole content at newlines:&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">for&lt;/span> &lt;span style="color:#000">_&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">line&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">range&lt;/span> &lt;span style="color:#000">strings&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Split&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#204a87">string&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">rawData&lt;/span>&lt;span style="color:#000;font-weight:bold">),&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;\n&amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// parse line into an instruction
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/li>
&lt;li>
&lt;p>Another option to read a file line by line would be to use &lt;a href="https://pkg.go.dev/bufio#Scanner" target="_blank" rel="noopener" class="godoc">bufio.Scanner&lt;/a>
&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/details>
&lt;details >
&lt;summary>Parse line&lt;/summary>
&lt;ul>
&lt;li>
&lt;p>The &lt;a href="https://pkg.go.dev/strings" target="_blank" rel="noopener" class="godoc">strings&lt;/a>
package contains a lot of other useful functions to work with strings (eg. &lt;a href="https://pkg.go.dev/strings#Cut" target="_blank" rel="noopener" class="godoc">strings.Cut&lt;/a>
or &lt;a href="https://pkg.go.dev/strings#Fields" target="_blank" rel="noopener" class="godoc">strings.Fields&lt;/a>
).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>You can convert a string into an integer using &lt;a href="https://pkg.go.dev/strconv#Atoi" target="_blank" rel="noopener" class="godoc">strconv.Atoi&lt;/a>
from the &lt;a href="https://pkg.go.dev/strconv" target="_blank" rel="noopener" class="godoc">strconv&lt;/a>
package.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/details>
&lt;details >
&lt;summary>Represent data&lt;/summary>
&lt;ul>
&lt;li>You can represent directions (&lt;code>up&lt;/code>, &lt;code>right&lt;/code>, etc.) as integers:&lt;/li>
&lt;/ul>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">const&lt;/span> &lt;span style="color:#000;font-weight:bold">(&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">UP&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">RIGHT&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">DOWN&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">2&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">LEFT&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">3&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;ul>
&lt;li>Keep related state together in a struct. For example an instruction could look like this:&lt;/li>
&lt;/ul>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span> &lt;span style="color:#000">Instruction&lt;/span> &lt;span style="color:#204a87;font-weight:bold">struct&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Direction&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Distance&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>And a postion could look like this:&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span> &lt;span style="color:#000">Position&lt;/span> &lt;span style="color:#204a87;font-weight:bold">struct&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">X&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Y&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">func&lt;/span> &lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">p&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">*&lt;/span>&lt;span style="color:#000">Position&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000">Move&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">direction&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">distance&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// update coordinates accordingly
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;details >
&lt;summary>Skeleton (Code strucutre)&lt;/summary>
&lt;p>There are many ways on how to structure your code. If you have no idea how to start you can use the following skeleton:&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">const&lt;/span> &lt;span style="color:#000;font-weight:bold">(&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">UP&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">RIGHT&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">DOWN&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">2&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">LEFT&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">3&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span> &lt;span style="color:#000">Instruction&lt;/span> &lt;span style="color:#204a87;font-weight:bold">struct&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Direction&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Distance&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span> &lt;span style="color:#000">Position&lt;/span> &lt;span style="color:#204a87;font-weight:bold">struct&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">X&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Y&lt;/span> &lt;span style="color:#204a87;font-weight:bold">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">func&lt;/span> &lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">p&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">*&lt;/span>&lt;span style="color:#000">Position&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000">Move&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">i&lt;/span> &lt;span style="color:#000">Instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// update position
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#8f5902;font-style:italic">// e.g. p.X += i.Distance
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">func&lt;/span> &lt;span style="color:#000">main&lt;/span>&lt;span style="color:#000;font-weight:bold">()&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// read/parse instructions from file
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#000">instructions&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">readInstructions&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;input.txt&amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">!=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// handle error
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// create your initial position
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#000">pos&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">Postion&lt;/span>&lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">X&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">0&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Y&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">0&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// loop over the instructions
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#204a87;font-weight:bold">for&lt;/span> &lt;span style="color:#000">_&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">i&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">range&lt;/span> &lt;span style="color:#000">instructions&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// adjust your position accordingly
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#000">pos&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Move&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">i&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// print final position
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#000">fmt&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Println&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">pos&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">func&lt;/span> &lt;span style="color:#000">readInstructions&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">fileName&lt;/span> &lt;span style="color:#204a87;font-weight:bold">string&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">([]&lt;/span>&lt;span style="color:#000">Instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#204a87;font-weight:bold">error&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">instructions&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000;font-weight:bold">[]&lt;/span>&lt;span style="color:#000">Instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">{}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// iterate over lines in file and fill instructions slice
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#204a87;font-weight:bold">for&lt;/span> &lt;span style="color:#000">_&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">line&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">range&lt;/span> &lt;span style="color:#000">lines&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">parseInstruction&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">line&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">!=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">instructions&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#204a87">append&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">instructions&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">*&lt;/span>&lt;span style="color:#000">instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#000">instructions&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">func&lt;/span> &lt;span style="color:#000">parseInstruction&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">line&lt;/span> &lt;span style="color:#204a87;font-weight:bold">string&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">*&lt;/span>&lt;span style="color:#000">Instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#204a87;font-weight:bold">error&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// split line
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// read direction and distance
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// return instruction
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">&amp;amp;&lt;/span>&lt;span style="color:#000">Instruction&lt;/span>&lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Direction&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span> &lt;span style="color:#000">direction&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Distance&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span> &lt;span style="color:#000">distance&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">},&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;h2 id="solution">Solution&lt;/h2>
&lt;details >
&lt;summary>Result&lt;/summary>
&lt;ul>
&lt;li>end position: &lt;code>19,20&lt;/code>&lt;/li>
&lt;li>most left position: &lt;code>-3&lt;/code>&lt;/li>
&lt;li>most right position: &lt;code>25&lt;/code>&lt;/li>
&lt;li>most visited position: &lt;code>18,7&lt;/code> (5 times)&lt;/li>
&lt;/ul>
&lt;/details>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/robot" target="_blank" rel="noopener" >https://github.com/acend/go-basics-training-examples/tree/master/robot&lt;/a>
&lt;/p></description></item><item><title>Docs: Joke API</title><link>/docs/exercises/lab_joke_api/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/exercises/lab_joke_api/</guid><description>
&lt;h2 id="task">Task&lt;/h2>
&lt;p>Try and solve the following. Every task has links to relevant documentation.&lt;/p>
&lt;h3 id="api-client">API Client&lt;/h3>
&lt;ol>
&lt;li>Begin with the following &lt;a href="main.txt" >main.go&lt;/a>
which requests a joke from &lt;a href="https://official-joke-api.appspot.com/random_joke" target="_blank" rel="noopener" >https://official-joke-api.appspot.com/random_joke&lt;/a>
and decodes it into a Go struct.&lt;/li>
&lt;li>Refactor the HTTP request into another &lt;a href="/docs/basics/functions/" >function&lt;/a>
that returns &lt;code>joke, error&lt;/code>&lt;/li>
&lt;li>Update the code to also &lt;a href="/docs/standard-library/json/" >decode&lt;/a>
and print the punchline&lt;/li>
&lt;li>&lt;a href="https://pkg.go.dev/time#Sleep" target="_blank" rel="noopener" class="godoc">Delay&lt;/a>
the punchline by a few seconds&lt;/li>
&lt;li>Make the delay configurable with a &lt;code>--delay 10&lt;/code> &lt;a href="https://pkg.go.dev/flag" target="_blank" rel="noopener" class="godoc">flag&lt;/a>
&lt;/li>
&lt;/ol>
&lt;details >
&lt;summary>Some tips regarding flags&lt;/summary>
&lt;p>We recommend using &lt;a href="https://pkg.go.dev/flag#IntVar" target="_blank" rel="noopener" class="godoc">flag.IntVar&lt;/a>
, instead of &lt;a href="https://pkg.go.dev/flag#Int" target="_blank" rel="noopener" class="godoc">flag.Int&lt;/a>
. Both variants work, but with &lt;a href="https://pkg.go.dev/flag#IntVar" target="_blank" rel="noopener" class="godoc">flag.IntVar&lt;/a>
you end up with a normal variable, instead of a &lt;a href="/docs/basics/pointers/" >pointer&lt;/a>
. You may also try using &lt;a href="https://pkg.go.dev/flag#DurationVar" target="_blank" rel="noopener" class="godoc">flag.DurationVar&lt;/a>
.&lt;/p>
&lt;p>To learn more about the &lt;code>*int&lt;/code> type, see &lt;a href="/docs/basics/pointers/">2.4. Pointers&lt;/a>.&lt;/p>
&lt;p>Do not forget to run &lt;a href="https://pkg.go.dev/flag#Parse" target="_blank" rel="noopener" class="godoc">flag.Parse()&lt;/a>
after defining the flags.&lt;/p>
&lt;/details>
&lt;details >
&lt;summary>Error: mismatched types int and time.Duration&lt;/summary>
&lt;p>When solving the last task, you might receive the error: &lt;code>mismatched types int and time.Duration&lt;/code>. This is because you cannot multiply different types. You must first convert the value to the same type.&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">i&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">42&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">f&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87">float64&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">i&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">u&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87">uint&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">f&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">d&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">time&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Duration&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">u&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>For more information why &lt;code>5 * time.Second&lt;/code> works see:
&lt;a href="https://stackoverflow.com/a/49498375" target="_blank" rel="noopener" >https://stackoverflow.com/a/49498375&lt;/a>
&lt;/p>
&lt;/details>
&lt;h3 id="api-server">API Server&lt;/h3>
&lt;ol start="6">
&lt;li>Write another program that &lt;a href="https://pkg.go.dev/os#ReadFile" target="_blank" rel="noopener" class="godoc">reads&lt;/a>
a &lt;a href="https://github.com/15Dkatz/official_joke_api/blob/master/jokes/index.json" target="_blank" rel="noopener" >json file&lt;/a>
and picks a &lt;a href="https://pkg.go.dev/math/rand#Intn" target="_blank" rel="noopener" class="godoc">random&lt;/a>
joke. You will need to use &lt;a href="/docs/basics/slices" >slices&lt;/a>
&lt;/li>
&lt;li>Implement a &lt;a href="/docs/standard-library/http-server/" >HTTP Server&lt;/a>
that serves the picked joke&lt;/li>
&lt;li>Update your program from part one so that you can configure the URL (maybe as another flag) and query your own API&lt;/li>
&lt;/ol>
&lt;h3 id="add-jokes">Add jokes&lt;/h3>
&lt;ol start="9">
&lt;li>Extend your HTTP Server that you can send a joke to it which gets &lt;a href="/docs/standard-library/io/" >persisted&lt;/a>
(POST request)&lt;/li>
&lt;li>Extend your program from part one that it supports adding new jokes. For this ask the user to enter a joke on the command line (standard input) and &lt;a href="/docs/standard-library/http-client/" >send&lt;/a>
it to your own API.&lt;/li>
&lt;/ol>
&lt;details >
&lt;summary>Prompt for input on the command line (standard input)&lt;/summary>
&lt;p>With the &lt;a href="https://pkg.go.dev/bufio" target="_blank" rel="noopener" class="godoc">bufio&lt;/a>
package we can read from the standard input (&lt;a href="https://pkg.go.dev/os#Stdin" target="_blank" rel="noopener" class="godoc">os.Stdin&lt;/a>
) until a certain character occurs:&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">line&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">bufio&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">NewReader&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">os&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Stdin&lt;/span>&lt;span style="color:#000;font-weight:bold">).&lt;/span>&lt;span style="color:#000">ReadString&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#39;\n&amp;#39;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>The &lt;a href="https://pkg.go.dev/strings" target="_blank" rel="noopener" class="godoc">strings&lt;/a>
package contains various functions to work with strings. For example &lt;a href="https://pkg.go.dev/strings#TrimSpace" target="_blank" rel="noopener" class="godoc">strings.TrimSpace&lt;/a>
to remove whithspace characters (spaces, newlines, etc.) from strings.&lt;/p>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">line&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#000">strings&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">TrimSpace&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">line&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;h2 id="solution">Solution&lt;/h2>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/joke-api-client" target="_blank" rel="noopener" >Client&lt;/a>
&lt;/p>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/joke-api-server" target="_blank" rel="noopener" >Server&lt;/a>
&lt;/p>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/joke-api-full" target="_blank" rel="noopener" >Full Combined&lt;/a>
&lt;/p></description></item><item><title>Docs: HTTP Client</title><link>/docs/exercises/lab_http_client/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/exercises/lab_http_client/</guid><description>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>We will write a small CLI tool that gets the follower count and the full name of a specific Github user.&lt;/p>
&lt;p>Information about a Github user we can obtain from the Github REST API under &lt;code>https://api.github.com/users/&amp;lt;user&amp;gt;&lt;/code>.
Besides many other information a call to &lt;a href="https://api.github.com/users/mitchellh" target="_blank" rel="noopener" >https://api.github.com/users/mitchellh&lt;/a>
returns the following information:&lt;/p>
&lt;pre tabindex="0">&lt;code>{
&amp;#34;login&amp;#34;: &amp;#34;mitchellh&amp;#34;,
...
&amp;#34;name&amp;#34;: &amp;#34;Mitchell Hashimoto&amp;#34;,
...
&amp;#34;followers&amp;#34;: 9973,
...
}
&lt;/code>&lt;/pre>&lt;p>The Github API limits the number of unauthenticated requests per IP to 60 per hour. So it is likely that you get a HTTP response code of 429 (Too Many Requests) and no answer.&lt;/p>
&lt;p>To send more requests from one IP you have to &lt;a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token" target="_blank" rel="noopener" >generate a personal access token&lt;/a>
(you don&amp;rsquo;t have to select any permission/scope) and send it as part of the &lt;code>Authorization&lt;/code> header:&lt;/p>
&lt;pre tabindex="0">&lt;code>Authorization: Bearer &amp;lt;your token&amp;gt;
&lt;/code>&lt;/pre>&lt;h2 id="tasks">Tasks&lt;/h2>
&lt;ol>
&lt;li>Create CLI tool &lt;code>github-info&lt;/code> which takes a username as argument and prints the users full name and the number of followers.&lt;/li>
&lt;li>Read the personal access token from the environment variable &lt;code>GITHUB_TOKEN&lt;/code> and send it with the API request.&lt;/li>
&lt;li>Github returns info about the ratelimiting in the HTTP headers of the response. Add an option &lt;code>-debug&lt;/code> which shows the number of remaining requests (header &lt;code>x-ratelimit-remaining&lt;/code>).&lt;/li>
&lt;/ol>
&lt;p>The result should look similar to this:&lt;/p>
&lt;pre tabindex="0">&lt;code>$ ./github-info mitchellh
name: Mitchell Hashimoto
followers: 9973
&lt;/code>&lt;/pre>&lt;p>After task 3 with debug flag:&lt;/p>
&lt;pre tabindex="0">&lt;code>$ ./github-info -debug mitchellh
remaining requests: 48
name: Mitchell Hashimoto
followers: 9973
&lt;/code>&lt;/pre>&lt;h2 id="tips">Tips&lt;/h2>
&lt;p>Check out the examples in &lt;a href="/docs/standard-library/http-client/">5.3. HTTP Client&lt;/a> and &lt;a href="/docs/standard-library/json/">5.2. JSON&lt;/a>.&lt;/p>
&lt;details >
&lt;summary>Standard library packages&lt;/summary>
&lt;ul>
&lt;li>To get arguments from the command line see &lt;a href="https://pkg.go.dev/os" target="_blank" rel="noopener" class="godoc">os&lt;/a>
or &lt;a href="https://pkg.go.dev/flag" target="_blank" rel="noopener" class="godoc">flag&lt;/a>
&lt;/li>
&lt;li>&lt;a href="https://pkg.go.dev/net/http" target="_blank" rel="noopener" class="godoc">net/http&lt;/a>
&lt;ul>
&lt;li>Especially take a look at &lt;a href="https://pkg.go.dev/net/http#Response" target="_blank" rel="noopener" class="godoc">http.Response&lt;/a>
because we have to check the HTTP status code and read information from the response headers.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;a href="https://pkg.go.dev/encoding/json" target="_blank" rel="noopener" class="godoc">encoding/json&lt;/a>
&lt;/li>
&lt;/ul>
&lt;/details>
&lt;details >
&lt;summary>Parse flags and arguments&lt;/summary>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">debug&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">false&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">flag&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">BoolVar&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">&amp;amp;&lt;/span>&lt;span style="color:#000">debug&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;debug&amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">debug&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;show additional information about rate limiting&amp;#34;&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">flag&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Parse&lt;/span>&lt;span style="color:#000;font-weight:bold">()&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">flag&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">NArg&lt;/span>&lt;span style="color:#000;font-weight:bold">()&lt;/span> &lt;span style="color:#000;font-weight:bold">&amp;lt;&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">1&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// missing arugments
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">userName&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">flag&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Arg&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#0000cf;font-weight:bold">0&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;h2 id="solution">Solution&lt;/h2>
&lt;p>&lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/github-info" target="_blank" rel="noopener" >https://github.com/acend/go-basics-training-examples/tree/master/github-info&lt;/a>
&lt;/p></description></item><item><title>Docs: HTTP Server</title><link>/docs/exercises/lab_http_server/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/exercises/lab_http_server/</guid><description>
&lt;h2 id="part-1-ping-and-logger">Part 1: Ping and Logger&lt;/h2>
&lt;h3 id="tasks">Tasks&lt;/h3>
&lt;ol>
&lt;li>Run a server and implement a handler which returns &lt;code>pong&lt;/code> on the endpoint &lt;code>/ping&lt;/code>.&lt;/li>
&lt;li>Create a middleware to log every request. Log the path, method, duration and the IP of the client of the request.&lt;/li>
&lt;/ol>
&lt;p>Your log should look similar to this:&lt;/p>
&lt;pre tabindex="0">&lt;code>2022/04/11 10:03:08 remote=192.168.1.143 path=/foo method=GET duration=13.765874ms
&lt;/code>&lt;/pre>&lt;h3 id="tips">Tips&lt;/h3>
&lt;p>See &lt;a href="/docs/standard-library/http-server/">5.4. HTTP Server&lt;/a>.&lt;/p>
&lt;details >
&lt;summary>Standard library packages&lt;/summary>
&lt;ul>
&lt;li>Consider using the &lt;a href="https://pkg.go.dev/log" target="_blank" rel="noopener" class="godoc">log&lt;/a>
package from the standard library&lt;/li>
&lt;li>You can measure time using the &lt;a href="https://pkg.go.dev/time" target="_blank" rel="noopener" class="godoc">time&lt;/a>
package:&lt;/li>
&lt;/ul>
&lt;/details>
&lt;details >
&lt;summary>Measure duration&lt;/summary>
&lt;div >
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">start&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">time&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Now&lt;/span>&lt;span style="color:#000;font-weight:bold">()&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">// perform action
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>&lt;span style="color:#000">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">duration&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">time&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Now&lt;/span>&lt;span style="color:#000;font-weight:bold">().&lt;/span>&lt;span style="color:#000">Sub&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">start&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;/details>
&lt;h2 id="part-2-user-api">Part 2: User API&lt;/h2>
&lt;h3 id="tasks-1">Tasks&lt;/h3>
&lt;p>Create a JSON REST API where you can create, list and delete users.&lt;/p>
&lt;p>The API should provide the following endpoints:&lt;/p>
&lt;ul>
&lt;li>&lt;code>POST /user&lt;/code>: create a user&lt;/li>
&lt;li>&lt;code>GET /user&lt;/code>: returns all users&lt;/li>
&lt;li>&lt;code>GET /user/&amp;lt;ID&amp;gt;&lt;/code>: returns a single user by ID&lt;/li>
&lt;li>&lt;code>DELETE /user/&amp;lt;ID&amp;gt;&lt;/code>: delete user by ID&lt;/li>
&lt;/ul>
&lt;p>The user should look like this:&lt;/p>
&lt;pre tabindex="0">&lt;code>{
&amp;#34;name&amp;#34;: &amp;#34;john&amp;#34;,
&amp;#34;full_name&amp;#34;: &amp;#34;John Doe&amp;#34;,
&amp;#34;followers&amp;#34;: 13
}
&lt;/code>&lt;/pre>&lt;p>You can decide how you would like to store the users. One option would be to store them only in-memory for example in a map &lt;code>map[int]User&lt;/code>. Another option would be to store serialize the users into a file (e.g. with JSON).&lt;/p>
&lt;h3 id="tips-1">Tips&lt;/h3>
&lt;p>See &lt;a href="/docs/standard-library/http-server/">5.4. HTTP Server&lt;/a>.&lt;/p>
&lt;h2 id="part-3-user-api-client">Part 3: User API Client&lt;/h2>
&lt;h3 id="tasks-2">Tasks&lt;/h3>
&lt;p>Create CLI tool to list, create and delete users:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic"># create user&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./usercli create bob
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./usercli create bob &lt;span style="color:#4e9a06">&amp;#34;Bob Meier&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./usercli create bob &lt;span style="color:#4e9a06">&amp;#34;Bob Meier&amp;#34;&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">34&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic"># list all users&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./usercli get
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic"># show specific user&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./usercli get bob
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic"># delete user&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./usercli delete bob
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="tips-2">Tips&lt;/h3>
&lt;p>Take a look at the &lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/github-info-client" target="_blank" rel="noopener" >github-info-client&lt;/a>
example to get an idea on how to implement this.&lt;/p>
&lt;h2 id="solutions">Solutions&lt;/h2>
&lt;ul>
&lt;li>Part 1: Ping and Log Middleware: &lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/http-server" target="_blank" rel="noopener" >https://github.com/acend/go-basics-training-examples/tree/master/http-server&lt;/a>
&lt;/li>
&lt;li>Part 2 + 3: User API: &lt;a href="https://github.com/acend/go-basics-training-examples/tree/master/user-api" target="_blank" rel="noopener" >https://github.com/acend/go-basics-training-examples/tree/master/user-api&lt;/a>
&lt;/li>
&lt;/ul></description></item></channel></rss>