<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Golang, from zero to hero in the Go Programming language]]></title><description><![CDATA[Golang, The Go programming language blog, tutorials articles and videos]]></description><link>https://go.mohamedallam.tech</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1662293027348/opTB0n3Ii.jpg</url><title>Golang, from zero to hero in the Go Programming language</title><link>https://go.mohamedallam.tech</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 12 May 2026 21:20:08 GMT</lastBuildDate><atom:link href="https://go.mohamedallam.tech/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Physical vs Logical vs Abstract Data Types (DST) and data structure (DS)]]></title><description><![CDATA[Physical vs Logical vs Abstract Data Types (DST) and data structure (DS)
All computer science is about abstraction as everything is binary, and that's why its sometimes hard to learn, let's break down this terminology.
Abstract data types
Also known ...]]></description><link>https://go.mohamedallam.tech/physical-vs-logical-vs-abstract-data-types-dst-and-data-structure-ds</link><guid isPermaLink="true">https://go.mohamedallam.tech/physical-vs-logical-vs-abstract-data-types-dst-and-data-structure-ds</guid><category><![CDATA[General Programming]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[data structures]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Go Language]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Sat, 17 Dec 2022 00:01:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1671238558983/Nliiew3zq.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-physical-vs-logical-vs-abstract-data-types-dst-and-data-structure-ds">Physical vs Logical vs Abstract Data Types (DST) and data structure (DS)</h2>
<p>All computer science is about abstraction as everything is binary, and that's why its sometimes hard to learn, let's break down this terminology.</p>
<h2 id="heading-abstract-data-types">Abstract data types</h2>
<p>Also known as ADT, let's start our discussion about the primitives or scalar types.</p>
<ul>
<li><p>Abstract data types are abstracting away 0 and 1 from us,</p>
</li>
<li><p>Representation and operations, each data type, is represented in some specific way and can have a set of operations to it.</p>
<ul>
<li><p>16 bit integer is 15 bits of 1 and 0, and the leftmost bit is whether its a signed or unsigned integer.</p>
</li>
<li><p>Arithmetic Operations can be done on integers addition, subtraction, multiplication division modulos</p>
<ul>
<li>Relational operations, less than greater than, increment than decrement..etc</li>
</ul>
</li>
</ul>
</li>
<li><p>Primitives or scalar types, is the programming language provided types, like integers, strings, floats..ect</p>
</li>
<li><p>We dont concern our selves too much how internally this operations are performed.</p>
</li>
</ul>
<p>When we learn programming languages, we mostly learn about representation of data, mostly scalar types, or primitive types and the operations we can do to them.</p>
<p>So the concept of representation and definition of data, and operations on the. while hiding the internal details is in essence abstract data types</p>
<p>For example in programming languages, we define classes, which has objects, and we give those special behaviours and different details, this is how we define them and there operations. for example we can create a class of linkedlists, with different operations</p>
<ul>
<li><p>Add(element, index) or inserrt(element, index)</p>
</li>
<li><p>Append(element)</p>
</li>
<li><p>Remove(element)</p>
</li>
<li><p>Set(element)</p>
</li>
<li><p>Get(index)</p>
</li>
<li><p>Search(key)</p>
</li>
<li><p>Sort()</p>
</li>
<li><p>….</p>
</li>
</ul>
<p>This is how we create our own abstract data types, but the thing is, there is some very known and efficient data types, we call them data structure, they allow us to efficiently utilize the resources, the main memory in the most ideal way, and we extend the programming languages to perform what we want us, us developers.</p>
<h2 id="heading-physical-data-structure">Physical data structure</h2>
<p>Data structure is collection of data structure, so multiple data stored together.</p>
<p>This data structure defines how memory is allocated, they define how the memory will be organized in order for them to store the data.</p>
<h3 id="heading-arrays">Arrays</h3>
<ul>
<li><p>Most programming languages supports arrays</p>
</li>
<li><p>its a collection of memory allocation, side by side, back to back.</p>
</li>
<li><p>Arrays are fixed size, or arrays size is static, we cannot increase or decrease an array size after its creation, we can only assign to it, or desctruct it (deallocate the memory)</p>
</li>
<li><p>Arrays can be created in the stack or the heap, we use a pointer to allocate arrays in the heap.</p>
</li>
<li><p>We use arrays when we know the maximum number of elements we need</p>
</li>
</ul>
<h3 id="heading-linedlist">Linedlist</h3>
<ul>
<li><p>Lined lists are dynamic by nature, you can add more elements or delete them.</p>
</li>
<li><p>its a collceiton of data, where each piece is called a node</p>
</li>
<li><p>Each node holds data, and a pointer to the next node.</p>
</li>
<li><p>Lined lists live in the heap, the head pointer can be in the stack.</p>
</li>
</ul>
<h2 id="heading-logical-data-structure">Logical data structure</h2>
<p>This data structure, are an abstraction over the physical datastructure, Physical data structure store the data in memory, physically, but the logical data strucutre is the protocol, the discipline or the set of rules and policies we use to use the physical data structures in way we want for better organiztion of our data.</p>
<p>All operations we do to this data structure are defined also by the logic we set. the API.</p>
<p>This data structure can be split into two types, linear data structure, and non linear data structure.</p>
<h3 id="heading-linear-data-sturcture">Linear data sturcture</h3>
<p>linear data structure include</p>
<ul>
<li><p>Stack (LIFO)</p>
</li>
<li><p>Queue (FIFO)</p>
</li>
</ul>
<h3 id="heading-non-linear-data-structure">Non linear data structure</h3>
<ul>
<li><p>Tree</p>
</li>
<li><p>Graph</p>
</li>
</ul>
<h3 id="heading-tabluar">Tabluar</h3>
<ul>
<li>Hash tables</li>
</ul>
<h2 id="heading-big-o-notatian">Big O notatian</h2>
<p>Its how we analyse algorithms and operations on them, how efficient they are specially when we approach infinity. in respect of N input.</p>
<h3 id="heading-time-complexity">Time complexity</h3>
<p>To measure the performance of our data structure, our job is to find out how much work we do per N elements, means for example if to find a word in a dictionary takes you iterating through every single word, means thats Order of N, if you can find the word by just looking at a fraction of the book or a subset, there is high chances, its a log to the two of N, so time complexity is always in respect of our input, or how much element exists in the data we are working with, the job is not to find the exact time it takes, because that varies from machine to machine or from buzy processors to another..ect Our job is to find the least amount of time we need to process N elements, we analyse the behaviour, how much more time we need to get the task done. a behaviour not an exact time.</p>
<h3 id="heading-space-complexity">Space complexity</h3>
<p>Many times, when we do something, we need extra memory than what we are working with, so in that case, we would have to consider that, because we dont always have extra memory, so thats the memory complexity it can be order of N or less or more, depends on the data type or algorithm we are working with.</p>
<ul>
<li><p><a target="_blank" href="https://www.bigocheatsheet.com/">https://www.bigocheatsheet.com/</a></p>
</li>
<li><p><a target="_blank" href="https://www-cs-faculty.stanford.edu/~knuth/taocp.html">https://www-cs-faculty.stanford.edu/~knuth/taocp.html</a></p>
</li>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/Big_O_notation">https://en.wikipedia.org/wiki/Big_O_notation</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Trees data structure with types (uses cases included)]]></title><description><![CDATA[This articles breakdown the terminology used in trees data structure, as well as some types of trees and their use cases, to get familiar with them.

Trees types and use cases
Whats a tree
A tree is a collection of nodes, each node holds some data, o...]]></description><link>https://go.mohamedallam.tech/trees-data-structure-with-types-and-use-cases</link><guid isPermaLink="true">https://go.mohamedallam.tech/trees-data-structure-with-types-and-use-cases</guid><category><![CDATA[Go Language]]></category><category><![CDATA[data structures]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Fri, 09 Dec 2022 20:55:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1670619249726/x-soe4b2c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This articles breakdown the terminology used in trees data structure, as well as some types of trees and their use cases, to get familiar with them.</p>

<h1 id="heading-trees-types-and-use-cases">Trees types and use cases</h1>
<h2 id="heading-whats-a-tree">Whats a tree</h2>
<p>A tree is a collection of nodes, each node holds some data, one of the nodes is the root node, and other nodes. are disjoints subsets and each subset is a tree or a sub tree.</p>
<p>Each node has exactly one parent, and can have one or more children, no single node has more than one parent.</p>
<p>Trees are everywhere:</p>
<ul>
<li>If you wrote any switch statement but didnt knew why its more efficient than a bunch of if-else statements, <a target="_blank" href="https://en.wikipedia.org/wiki/Lookup_table">the answer is Look up tables (LUT) which may use BST</a></li>
<li>Operating systems use trees for <a target="_blank" href="https://en.wikipedia.org/wiki/File_system">File system</a>.</li>
<li>The syntactic representation of a programming language is Abstract syntax tree. <a target="_blank" href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">AST</a></li>
<li>Browser Document object model (<a target="_blank" href="https://en.wikipedia.org/wiki/Document_Object_Model">DOM</a>)</li>
<li>Databases use Log structured merge tree. <a target="_blank" href="https://en.wikipedia.org/wiki/Log-structured_merge-tree">LSM</a> tree</li>
<li>SQL index use <a target="_blank" href="https://en.wikipedia.org/wiki/B%2B_tree">b-tree</a>.</li>
<li>Dynamic memory management uses <a target="_blank" href="https://en.wikipedia.org/wiki/Memory_management#Dynamic_memory_allocation">heap</a>. which is a type of a tree.</li>
<li>A trie for dictionaries or <a target="_blank" href="https://www.geeksforgeeks.org/auto-complete-feature-using-trie/">auto complete algorithms.</a></li>
<li>Priority queues as well use <a target="_blank" href="https://www.geeksforgeeks.org/priority-queue-using-binary-heap/">heap</a>.</li>
<li>Garbage collectors also <a target="_blank" href="https://en.wikipedia.org/wiki/Tracing_garbage_collection">use trees</a>.</li>
</ul>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Tree_(graph_theory)">https://en.wikipedia.org/wiki/Tree_(graph_theory)</a></p>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Tree_(data_structure)">https://en.wikipedia.org/wiki/Tree_(data_structure)</a></p>
<h3 id="heading-nodes-or-vertices">Nodes or vertices</h3>
<p>Nodes is every unit of data</p>
<h3 id="heading-edges-or-paths-links">Edges or paths (links)</h3>
<p>Its the connection between each two nodes, if we have N nodes we would have N-1 edges, because each node as parent, except the root node.</p>
<h3 id="heading-root">Root</h3>
<p>Is the upmost node, who has no parent, and have only children,  for the children nodes this is their most parent node, generally in the top of the tree.</p>
<h3 id="heading-parent-children">Parent-Children</h3>
<p>A node is a parent to its very next descendants. the descendants are the children to whom its connected with one single edge.</p>
<h3 id="heading-siblings">Siblings</h3>
<p>Are the children connected to the same node.</p>
<h3 id="heading-descendants">Descendants</h3>
<p>When we want to talk about children and their children, and the children of their children..etc we would say descendants.</p>
<p>It means the set of nodes we can reach from a particular node going to its children. so all the subtree.</p>
<h3 id="heading-ansestors">Ansestors</h3>
<p>From that node to the root node, all this nodes are considered anscestors.</p>
<h3 id="heading-degree-of-nodes">Degree of nodes</h3>
<p>Is the number of children a node has, so the direct children.</p>
<p>A degree of a tree cannot be told from a tree, but its predefined, we can say its a binary tree. but if its unbalanced, we would see it in a form of a linkedlist.</p>
<h3 id="heading-leaf-nodes-external-or-terminal">Leaf nodes, external or terminal</h3>
<p>All nodes who has no children. so with nodes with degree 0</p>
<h3 id="heading-levels">Levels</h3>
<p>Levels starting from first level 1, the root, as we categorize each level by all the nodes who take the same number of edges to get to the root node.</p>
<h3 id="heading-height">Height</h3>
<p>Hight of nodes, is the same as the levels but it starts from 0, its very useful for analysis.</p>
<h3 id="heading-forest">Forest</h3>
<p>A collection of a tree is called a forest. which at least has a root node.</p>
<p>To convert a forest to a tree, we attach the roots of the present trees, to one single root.</p>
<h2 id="heading-types-of-trees">Types of trees</h2>
<p>There is many types of trees, and they are extremely useful and popular. for example</p>
<h3 id="heading-binary-tree">Binary tree</h3>
<p>One of the most popular trees, is <a target="_blank" href="https://en.wikipedia.org/wiki/Binary_tree">the binary tree</a>,</p>
<p>Its tree of degree 2, means every node can have 0,1 or 2 children, but not more than 2.</p>
<p>$deg(T)=2$</p>
<p>$children={{0,1,2}}$</p>
<ul>
<li>Because the nodes can have only 2 nodes, we call them left child and right child. or left node and right node.</li>
<li>If we come across a tree that is unbalanced, means it forms something like a linked list, but to the left side, we call it left skewed binary tree. or right skewed binary tree</li>
</ul>
<h3 id="heading-binary-search-tree">Binary search tree</h3>
<p>The binary search tree or <a target="_blank" href="https://en.wikipedia.org/wiki/Binary_search_tree">BST</a> , is a derivate of binary tree, but with a constraint in the data, Its a rooted binary tree, where every node (data) on the left side is grater than nodes on the right side.</p>
<p>$deg(T)=2$</p>
<h3 id="heading-avl-tree">AVL Tree</h3>
<p>Another tree named after inventors <strong>A</strong>delson-<strong>V</strong>elsky and <strong>L</strong>andis, is a self balancing binary search tree.</p>
<h3 id="heading-decision-tree">Decision Tree</h3>
<p>Its one of the popular ones for <a target="_blank" href="https://www.geeksforgeeks.org/decision-tree/">classification and prediction</a>.</p>
<h3 id="heading-fenwich-tree">Fenwich Tree</h3>
<p>A Fenwick tree or binary indexed tree is a data structure that can efficiently update elements and calculate <a target="_blank" href="https://en.wikipedia.org/wiki/Prefix_sum">prefix sums</a> in a table of numbers.</p>
<p>Link to <a target="_blank" href="https://en.wikipedia.org/wiki/Fenwick_tree">wiki</a></p>
<h3 id="heading-log-structured-merge-tree">Log structured Merge Tree</h3>
<p>Or LSM <a target="_blank" href="https://en.wikipedia.org/wiki/Log-structured_merge-tree">tree</a>  one of the trees used in databases like influxDB.</p>
]]></content:encoded></item><item><title><![CDATA[Golang test main function]]></title><description><![CDATA[This code shows how you can test the main function in Golang, using the official testing package.
It compiles to an executable file, runs it, and makes sure there is no errors, its also used for other tests in the same main package.
func TestMain(m *...]]></description><link>https://go.mohamedallam.tech/golang-test-main-function</link><guid isPermaLink="true">https://go.mohamedallam.tech/golang-test-main-function</guid><category><![CDATA[Go Language]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Testing]]></category><category><![CDATA[TDD (Test-driven development)]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Sat, 03 Dec 2022 14:34:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1670077910943/nnJovKtBa.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This code shows how you can test the main function in Golang, using the official testing package.</p>
<p>It compiles to an executable file, runs it, and makes sure there is no errors, its also used for other tests in the same main package.</p>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">TestMain</span><span class="hljs-params">(m *testing.M)</span></span> {
    fmt.Println(<span class="hljs-string">"-&gt; Building..."</span>)
    <span class="hljs-comment">// checking if Microsoft Windows OS</span>
    <span class="hljs-comment">// if so, we append .exe to make it excutable by Go</span>
    <span class="hljs-keyword">if</span> runtime.GOOS == <span class="hljs-string">"windows"</span> {
        appName += <span class="hljs-string">".exe"</span>
    }
    <span class="hljs-comment">// We run a command to build the code</span>
    <span class="hljs-comment">// we are using appName string as tthe name of the excutable</span>
    build := exec.Command(<span class="hljs-string">"go"</span>, <span class="hljs-string">"build"</span>, <span class="hljs-string">"-o"</span>, appName)
    <span class="hljs-keyword">if</span> err := build.Run(); err != <span class="hljs-literal">nil</span> {
        fmt.Fprintf(os.Stderr, <span class="hljs-string">"Error building %s: %s"</span>, appName, err)
        os.Exit(<span class="hljs-number">1</span>)
    }
    fmt.Println(<span class="hljs-string">"-&gt; Running..."</span>)
    <span class="hljs-comment">// Running the</span>
    result := m.Run()
    fmt.Println(<span class="hljs-string">"-&gt; Getting done..."</span>)
    os.Remove(appName)
    os.Remove(fileName)
    os.Exit(result)
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[The list of Go programming language target OS]]></title><description><![CDATA[Go tool dist list

This is the list of operating systems and architectures, Golang supports out of the box:g
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm...]]></description><link>https://go.mohamedallam.tech/the-list-of-go-programming-language-target-os</link><guid isPermaLink="true">https://go.mohamedallam.tech/the-list-of-go-programming-language-target-os</guid><category><![CDATA[General Programming]]></category><category><![CDATA[Linux]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Go Language]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Sat, 03 Dec 2022 12:08:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1670068997411/g8XrZukAP.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<pre><code class="lang-go">Go tool dist list
</code></pre>
<p>This is the list of operating systems and architectures, Golang supports out of the box:g</p>
<pre><code class="lang-plaintext">aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
freebsd/arm64
illumos/amd64
ios/amd64
ios/arm64
js/wasm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/loong64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/riscv64
linux/s390x
netbsd/386
netbsd/amd64
netbsd/arm
netbsd/arm64
openbsd/386
openbsd/amd64
openbsd/arm
openbsd/arm64
openbsd/mips64
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64
windows/arm
windows/arm64
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Go make function]]></title><description><![CDATA[Fortunately, Go has many ways of memory allocation and value initialization, though, some of us don't know how to use them properly.
In this article, we are going to speak of the Go built-in function, make
How to use it, when, the parameters it does ...]]></description><link>https://go.mohamedallam.tech/go-make-function</link><guid isPermaLink="true">https://go.mohamedallam.tech/go-make-function</guid><category><![CDATA[Go Language]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[data structures]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Thu, 01 Dec 2022 11:24:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1669893558143/L5jVWjTie.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Fortunately, Go has many ways of memory allocation and value initialization, though, some of us don't know how to use them properly.</p>
<p>In this article, we are going to speak of the Go built-in function, <code>make</code></p>
<p>How to use it, when, the parameters it does accept and more.</p>
<h2 id="heading-make">Make</h2>
<p>In Go, <code>make</code> is a special built-in function, there is a similar one called <code>new</code> but that one is fairly different and has a different purpose.</p>
<p>The make function signature is as follows, it has 3 arguments, the first one is the <strong>type</strong>, the second is the <strong>length</strong> and the last is its <strong>capacity</strong>.</p>
<pre><code class="lang-go"><span class="hljs-comment">// package builtin</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">make</span><span class="hljs-params">(t Type, size ...IntegerType)</span> <span class="hljs-title">Type</span></span>
</code></pre>
<p>According to the official documentation:</p>
<blockquote>
<p>The make built-in function allocates and initializes an object of type slice, map, or chan (only). Like new, the first argument is a type, not a value. Unlike new, make's return type is the same as the type of its argument, not a pointer to it. The specification of the result depends on the type:</p>
<p>Slice: The size specifies the length. The capacity of the slice is equal to its length. A second integer argument may be provided to specify a different capacity; it must be no smaller than the length. For example, make([]int, 0, 10) allocates an underlying array of size 10 and returns a slice of length 0 and capacity 10 that is backed by this underlying array.</p>
<p>Map: An empty map is allocated with enough space to hold the specified number of elements. The size may be omitted, in which case a small starting size is allocated.</p>
<p>Channel: The channel's buffer is initialized with the specified buffer capacity. If zero, or the size is omitted, the channel is unbuffered.</p>
</blockquote>
<h3 id="heading-at-glance">At Glance</h3>
<p><code>make</code> function can take 3 parameters, but the first parameter is the only required one, which is the type, that we would return out of the function.</p>
<p>The <code>make</code> function, creates an underlying array for this type, and enables you to optionally define the starting length of the array, and the starting capacity.</p>
<ul>
<li><p>A type</p>
<ul>
<li><p>slice</p>
</li>
<li><p>map</p>
</li>
<li><p>channel</p>
</li>
</ul>
</li>
<li><p>length</p>
</li>
<li><p>capacity</p>
</li>
</ul>
<h3 id="heading-lets-break-it-down">Lets break it down</h3>
<h3 id="heading-type">Type</h3>
<p>The first argument in the make function, is the type we intend to create, So it applies only to the 3 built-in reference types: slices, maps and channels.<br />It's a function that allocates and initializes the specified object type, as discussed, So that's the variable type we return.</p>
<p>Unlike new, which returns a pointer to the data it has created and allocated space for you.</p>
<h3 id="heading-length">Length</h3>
<p>The optional second argument has to be of type integer, which is the length of the type we want to initialize. if we don’t specify anything it's initialized to 0, as for channel type, it would be an unbuffered channel.</p>
<h3 id="heading-capacity">Capacity</h3>
<p>The capacity is optional, it would be the underlying array we allocate for this type, the array should be of size bigger than the length, otherwise, it would throw an error.</p>
<blockquote>
<p><code>invalid argument: length and capacity swapped</code></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Golang: testing terminal output]]></title><description><![CDATA[When working with Go, we always strive to test, one thing we want to test, is the terminal output, this is a simple way for testing the standard output.
Testing the terminal output
// save copy of std out
old := os.Stdout
//create read and write pupe...]]></description><link>https://go.mohamedallam.tech/golang-testing-terminal-output</link><guid isPermaLink="true">https://go.mohamedallam.tech/golang-testing-terminal-output</guid><category><![CDATA[Go Language]]></category><category><![CDATA[terminal]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[coding]]></category><category><![CDATA[Testing]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Thu, 01 Dec 2022 10:49:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1669888571893/KFLDj7Gy3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When working with Go, we always strive to test, one thing we want to test, is the terminal output, this is a simple way for testing the standard output.</p>
<h2 id="heading-testing-the-terminal-output">Testing the terminal output</h2>
<pre><code class="lang-go"><span class="hljs-comment">// save copy of std out</span>
old := os.Stdout
<span class="hljs-comment">//create read and write pupe</span>
r, w, _ := os.Pipe()
<span class="hljs-comment">// set the stdout to the pipe</span>
os.Stdout = w
<span class="hljs-comment">// we excute the function</span>
someFunctionCall()
<span class="hljs-comment">// close the resource</span>
w.Close()
<span class="hljs-comment">// reset the stdout back to the orignal</span>
os.Stdout = old
<span class="hljs-comment">// read from the read pipe we create</span>
got, _ := io.ReadAll(r)
<span class="hljs-comment">// check if out is what you want</span>
<span class="hljs-comment">// want := something you want</span>
<span class="hljs-comment">//if got != want {</span>
    <span class="hljs-comment">// throw an error.</span>
<span class="hljs-comment">//}</span>
</code></pre>
<h2 id="heading-example">Example</h2>
<h3 id="heading-sayhello-function">SayHello function</h3>
<p>Given we have this example function, saying <code>Hello World!</code>, and we want to test this out, whether the terminal is properly printing it out.</p>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">sayHello</span><span class="hljs-params">()</span></span> {
    fmt.Printf(<span class="hljs-string">"Hello World!"</span>)
}
</code></pre>
<h3 id="heading-the-test-we-function">The test we function</h3>
<p>To test we apply the same method, and we test for strings equality.</p>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Test_SayHello</span><span class="hljs-params">(t *testing.T)</span></span> {
    <span class="hljs-comment">// save copy of std out</span>
    old := os.Stdout
    <span class="hljs-comment">//create read and write pupe</span>
    r, w, _ := os.Pipe()
    <span class="hljs-comment">// set the stdout to the pipe</span>
    os.Stdout = w
    <span class="hljs-comment">// we excuted</span>
    sayHello()
    <span class="hljs-comment">// close the resource</span>
    w.Close()
    <span class="hljs-comment">// reset the stdout back to the orignal</span>
    os.Stdout = old
    <span class="hljs-comment">// read from the read output we create</span>
    out, _ := io.ReadAll(r)
    <span class="hljs-comment">// convert to string</span>
    got := <span class="hljs-keyword">string</span>(out)
    <span class="hljs-comment">// what we expect</span>
    want := <span class="hljs-string">"Hello World!"</span>
    <span class="hljs-keyword">if</span> strings.Compare(got, want) != <span class="hljs-number">0</span> {
        t.Errorf(<span class="hljs-string">"incorrect hello got: %v"</span>, <span class="hljs-keyword">string</span>(out))
    }
    <span class="hljs-keyword">if</span> got != want {
        t.Errorf(<span class="hljs-string">"incorrect hello got: %v"</span>, <span class="hljs-keyword">string</span>(out))
    }
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Curated list of all Go books (Golang)]]></title><description><![CDATA[List of every Go book I found
I started learning Go, and I found plenty books and I didnt knew where to start from, so my first step was to collect them, I figured many others would need to do the same, or at least search for Go books to filter throu...]]></description><link>https://go.mohamedallam.tech/curated-list-of-all-go-books-golang</link><guid isPermaLink="true">https://go.mohamedallam.tech/curated-list-of-all-go-books-golang</guid><category><![CDATA[Web Development]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[books]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[list]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Sun, 20 Nov 2022 22:39:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/NIJuEQw0RKg/upload/v1668983772059/ops186P3I.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-list-of-every-go-book-i-found">List of every Go book I found</h1>
<p>I started learning Go, and I found plenty books and I didnt knew where to start from, so my first step was to collect them, I figured many others would need to do the same, or at least search for Go books to filter through and make their choice, so I hope this makes there journey easier.</p>
<p><em>The books are in no particular order</em></p>
<h3 id="heading-writing-an-interpreter-in-go"><strong>Writing an interpreter in Go</strong></h3>
<p>By Thorsten Ball </p>
<p>Released 23 November 2016</p>
<p>ISBN: <strong>3982016118</strong></p>
<p><a target="_blank" href="https://interpreterbook.com/">https://interpreterbook.com/</a></p>
<h3 id="heading-writing-a-compiler-in-go"><strong>Writing a compiler in Go</strong></h3>
<p>By Thorsten Ball</p>
<p>Released 31 July 2018</p>
<p>ISBN: <strong>398201610X</strong></p>
<p><a target="_blank" href="https://compilerbook.com/">https://compilerbook.com/</a></p>
<h3 id="heading-go-fundamentals-gopher-guides"><strong>Go fundamentals: Gopher Guides</strong></h3>
<p>By Mark Bates, Cory LaNou</p>
<p>Released November 2022</p>
<p>ISBN: 9780137918416</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-fundamentals-gopher/9780137918416/">https://www.oreilly.com/library/view/go-fundamentals-gopher/9780137918416/</a></p>
<h3 id="heading-efficient-go"><strong>Efficient Go</strong></h3>
<p>By Bartlomiej Plotka</p>
<p>Released November 2022</p>
<p>ISBN: 9781098105716</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/efficient-go/9781098105709/">https://www.oreilly.com/library/view/efficient-go/9781098105709/</a></p>
<h3 id="heading-learning-go"><strong>Learning Go</strong></h3>
<p>By Jon Bodner</p>
<p>Released March 2021</p>
<p>ISBN: 9781492077213</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/learning-go/9781492077206/">https://www.oreilly.com/library/view/learning-go/9781492077206/</a></p>
<h3 id="heading-mastering-go-third-edition"><strong>Mastering Go - Third Edition</strong></h3>
<p>By Mihalis Tsoukalos</p>
<p>Released August 2021</p>
<p>ISBN: 9781801079310</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/mastering-go/9781801079310/">https://www.oreilly.com/library/view/mastering-go/9781801079310/</a></p>
<h3 id="heading-mastering-go-second-edition"><strong>Mastering Go - Second Edition</strong></h3>
<p>By Mihalis Tsoukalos</p>
<p>Released August 2021</p>
<p>ISBN: 9781838559335</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/mastering-go/9781838559335/">https://www.oreilly.com/library/view/mastering-go/9781838559335/</a></p>
<h3 id="heading-head-first-go"><strong>Head First Go</strong></h3>
<p>By Jay McGavren</p>
<p>Released April 2019</p>
<p>ISBN: 9781491969557</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/head-first-go/9781491969540/">https://www.oreilly.com/library/view/head-first-go/9781491969540/</a></p>
<h3 id="heading-the-go-programming-language"><strong>The Go Programming Language</strong></h3>
<p>By Alan A. A. Donovan, Brian W. Kernighan</p>
<p>Released October 2015</p>
<p>ISBN: 9780134190570</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/the-go-programming/9780134190570/">https://www.oreilly.com/library/view/the-go-programming/9780134190570/</a></p>
<h3 id="heading-cloud-native-go"><strong>Cloud Native Go</strong></h3>
<p>By Matthew A. Titmus</p>
<p>Released April 2021</p>
<p>ISBN: 9781492076339</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/cloud-native-go/9781492076322/">https://www.oreilly.com/library/view/cloud-native-go/9781492076322/</a></p>
<h3 id="heading-pro-go-the-complete-guide-to-programming-reliable-and-efficient-software-using-golang"><strong>Pro Go: The Complete Guide to Programming Reliable and Efficient Software Using Golang</strong></h3>
<p>By Adam Freeman</p>
<p>Released January 2022</p>
<p>ISBN: 9781484273555</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/pro-go-the/9781484273555/">https://www.oreilly.com/library/view/pro-go-the/9781484273555/</a></p>
<h3 id="heading-concurrency-in-go"><strong>Concurrency in Go</strong></h3>
<p>By Katherine Cox-Buday</p>
<p>Released August 2017</p>
<p>ISBN: 9781491941195</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/concurrency-in-go/9781491941294/">https://www.oreilly.com/library/view/concurrency-in-go/9781491941294/</a></p>
<h3 id="heading-powerful-command-line-applications-in-go"><strong>Powerful Command-Line Applications in Go</strong></h3>
<p>by Ricardo Gerardi</p>
<p>Released December 2021</p>
<p>ISBN: 9781680509328</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/powerful-command-line-applications/9781680509311/">https://www.oreilly.com/library/view/powerful-command-line-applications/9781680509311/</a></p>
<h3 id="heading-go-in-24-hours-sams-teach-yourself-next-generation-systems-programming-with-golang-first-edition"><strong>Go in 24 Hours Sams Teach Yourself: Next Generation Systems Programming with Golang, First Edition</strong></h3>
<p>By George Ornbo</p>
<p>Released December 2017</p>
<p>ISBN: 9780134771922</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-in-24/9780134771922/">https://www.oreilly.com/library/view/go-in-24/9780134771922/</a></p>
<h3 id="heading-network-programming-with-go"><strong>Network Programming with Go</strong></h3>
<p>By Adam Woodbeck</p>
<p>Released March 2021</p>
<p>ISBN: 9781718500884</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/network-programming-with/9781098128890/">https://www.oreilly.com/library/view/network-programming-with/9781098128890/</a></p>
<h3 id="heading-hands-on-software-engineering-with-golang"><strong>Hands-On Software Engineering with Golang</strong></h3>
<p>By Achilleas Anagnostopoulos</p>
<p>Released January 2020</p>
<p>ISBN: 9781838554491</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-software-engineering/9781838554491/">https://www.oreilly.com/library/view/hands-on-software-engineering/9781838554491/</a></p>
<h3 id="heading-black-hat-go"><strong>Black Hat Go</strong></h3>
<p>by Tom Steele, Chris Patten, Dan Kottmann</p>
<p>Released January 2020</p>
<p>ISBN: 9781593278656</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/black-hat-go/9781098122645/">https://www.oreilly.com/library/view/black-hat-go/9781098122645/</a></p>
<h3 id="heading-introducing-go"><strong>Introducing Go</strong></h3>
<p>by Caleb Doxsey</p>
<p>Released January 2016</p>
<p>ISBN: 9781491941959</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/introducing-go/9781491941997/">https://www.oreilly.com/library/view/introducing-go/9781491941997/</a></p>
<h3 id="heading-go-in-action"><strong>Go in Action</strong></h3>
<p>by Brian Ketelsen, Erik St. Martin, and William Kennedy</p>
<p>Released November 2015</p>
<p>ISBN: 9781617291784</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-in-action/9781617291784/">https://www.oreilly.com/library/view/go-in-action/9781617291784/</a></p>
<h3 id="heading-go-web-programming"><strong>Go Web Programming</strong></h3>
<p>By Sau Sheong Chang</p>
<p>Released July 2016</p>
<p>ISBN: 9781617292569</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-web-programming/9781617292569/">https://www.oreilly.com/library/view/go-web-programming/9781617292569/</a></p>
<h3 id="heading-go-for-java-programmers"><strong>Go for Java Programmers</strong></h3>
<p>by Barry Feigenbaum Ph.D.</p>
<p>Released October 2021</p>
<p>ISBN: 9781484271995</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-for-java/9781484271995/">https://www.oreilly.com/library/view/go-for-java/9781484271995/</a></p>
<h3 id="heading-get-programming-with-go"><strong>Get Programming with Go</strong></h3>
<p>by Nathan Youngman and Roger Peppé</p>
<p>Released September 2018</p>
<p>ISBN: 9781617293092</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/get-programming-with/9781617293092/">https://www.oreilly.com/library/view/get-programming-with/9781617293092/</a></p>
<h3 id="heading-go-in-practice"><strong>Go in Practice</strong></h3>
<p>by Matt Butcher, Matt Farina</p>
<p>Released August 2016</p>
<p>ISBN: 9781633430075</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-in-practice/9781633430075/">https://www.oreilly.com/library/view/go-in-practice/9781633430075/</a></p>
<h3 id="heading-hands-on-restful-web-services-with-go-second-edition"><strong>Hands-On RESTful Web Services with Go - Second Edition</strong></h3>
<p>by Naren Yellavula</p>
<p>Released February 2020</p>
<p>ISBN: 9781838643577</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-restful-web/9781838643577/">https://www.oreilly.com/library/view/hands-on-restful-web/9781838643577/</a></p>
<h3 id="heading-building-restful-web-services-with-go"><strong>Building RESTful Web services with Go</strong></h3>
<p>by Naren Yellavula</p>
<p>Released December 2017</p>
<p>ISBN: 9781788294287</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/building-restful-web/9781788294287/">https://www.oreilly.com/library/view/building-restful-web/9781788294287/</a></p>
<h3 id="heading-hands-on-dependency-injection-in-go"><strong>Hands-On Dependency Injection in Go</strong></h3>
<p>by Corey Scott</p>
<p>Released November 2018</p>
<p>ISBN: 9781789132762</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-dependency-injection/9781789132762/">https://www.oreilly.com/library/view/hands-on-dependency-injection/9781789132762/</a></p>
<h3 id="heading-go-programming-blueprints-second-edition">Go Programming Blueprints <strong>- Second Edition</strong></h3>
<p>by Mat Ryer</p>
<p>Released October 2016</p>
<p>ISBN: 9781786468949</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-programming-blueprints/9781786468949/">https://www.oreilly.com/library/view/go-programming-blueprints/9781786468949/</a></p>
<h3 id="heading-go-programming-blueprints"><strong>Go Programming Blueprints</strong></h3>
<p>by Mat Ryer</p>
<p>Released January 2015</p>
<p>ISBN: 9781783988020</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-programming-blueprints/9781783988020/">https://www.oreilly.com/library/view/go-programming-blueprints/9781783988020/</a></p>
<h3 id="heading-hands-on-full-stack-development-with-go"><strong>Hands-On Full Stack Development with Go</strong></h3>
<p>by Mina Andrawos</p>
<p>Released March 2019</p>
<p>ISBN: 9781789130751</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-full-stack/9781789130751/">https://www.oreilly.com/library/view/hands-on-full-stack/9781789130751/</a></p>
<h3 id="heading-go-programming-cookbook-second-edition"><strong>Go Programming Cookbook - Second Edition</strong></h3>
<p>by Aaron Torres</p>
<p>Released July 2019</p>
<p>ISBN: 9781789800982</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-programming-cookbook/9781789800982/">https://www.oreilly.com/library/view/go-programming-cookbook/9781789800982/</a></p>
<h3 id="heading-cloud-native-go"><strong>Cloud Native Go</strong></h3>
<p>by Kevin Hoffman, Dan Nemeth</p>
<p>Released December 2016</p>
<p>ISBN: 9780134505787</p>
<p><strong>Building Web Applications and Microservices for the Cloud with Go and React</strong></p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/cloud-native-go/9780134505787/">https://www.oreilly.com/library/view/cloud-native-go/9780134505787/</a></p>
<h3 id="heading-go-standard-library-cookbook"><strong>Go Standard Library Cookbook</strong></h3>
<p>by Radomir Sohlich</p>
<p>Released February 2018</p>
<p>ISBN: 9781788475273</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-standard-library/9781788475273/">https://www.oreilly.com/library/view/go-standard-library/9781788475273/</a></p>
<h3 id="heading-go-systems-programming"><strong>Go Systems Programming</strong></h3>
<p>by Mihalis Tsoukalos</p>
<p>Released September 2017</p>
<p>ISBN: 9781787125643</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-systems-programming/9781787125643/">https://www.oreilly.com/library/view/go-systems-programming/9781787125643/</a></p>
<h3 id="heading-the-go-workshop"><strong>The Go Workshop</strong></h3>
<p>by Delio D'Anna, Andrew Hayes, Sam Hennessy, Jeremy Leasor, Gobin Sougrakpam, Daniel Szabo</p>
<p>Released December 2019</p>
<p>ISBN: 9781838647940</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/the-go-workshop/9781838647940/">https://www.oreilly.com/library/view/the-go-workshop/9781838647940/</a></p>
<h3 id="heading-hands-on-system-programming-with-go"><strong>Hands-On System Programming with Go</strong></h3>
<p>by Alex Guerrieri</p>
<p>Released July 2019</p>
<p>ISBN: 9781789804072</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-system-programming/9781789804072/">https://www.oreilly.com/library/view/hands-on-system-programming/9781789804072/</a></p>
<h3 id="heading-hands-on-high-performance-with-go"><strong>Hands-On High Performance with Go</strong></h3>
<p>by Bob Strecansky</p>
<p>Released March 2020</p>
<p>ISBN: 9781789805789</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-high-performance/9781789805789/">https://www.oreilly.com/library/view/hands-on-high-performance/9781789805789/</a></p>
<h3 id="heading-the-go-programming-language-phrasebook"><strong>The Go Programming Language Phrasebook</strong></h3>
<p>by David Chisnall</p>
<p>Released April 2012</p>
<p>ISBN: 9780132918961</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/the-go-programming/9780132918961/">https://www.oreilly.com/library/view/the-go-programming/9780132918961/</a></p>
<h3 id="heading-learning-go-programming"><strong>Learning Go Programming</strong></h3>
<p>by Vladimir Vivien</p>
<p>Released October 2016</p>
<p>ISBN: 9781784395438</p>
<p><a target="_blank" href="https://oreilly.com/library/view/learning-go-programming/9781784395438/">https://oreilly.com/library/view/learning-go-programming/9781784395438/</a></p>
<h3 id="heading-go-building-web-applications"><strong>Go: Building Web Applications</strong></h3>
<p>by Nathan Kozyra, Mat Ryer</p>
<p>Released August 2016</p>
<p>ISBN: 9781787123496</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-building-web/9781787123496/">https://www.oreilly.com/library/view/go-building-web/9781787123496/</a></p>
<h3 id="heading-go-cookbook"><strong>Go Cookbook</strong></h3>
<p>by Aaron Torres</p>
<p>Released June 2017</p>
<p>ISBN: 9781783286836</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-cookbook/9781783286836/">https://www.oreilly.com/library/view/go-cookbook/9781783286836/</a></p>
<h3 id="heading-machine-learning-with-go"><strong>Machine Learning With Go</strong></h3>
<p>by Daniel Whitenack</p>
<p>Released September 2017</p>
<p>ISBN: 9781785882104</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/machine-learning-with/9781785882104/">https://www.oreilly.com/library/view/machine-learning-with/9781785882104/</a></p>
<h3 id="heading-distributed-computing-with-go"><strong>Distributed Computing with Go</strong></h3>
<p>by V.N. Nikhil Anurag</p>
<p>Released February 2018</p>
<p>ISBN: 9781787125384</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/distributed-computing-with/9781787125384/">https://www.oreilly.com/library/view/distributed-computing-with/9781787125384/</a></p>
<h3 id="heading-tanmay-teaches-go-the-ideal-language-for-backend-developers"><strong>Tanmay Teaches Go The Ideal Language for Backend Developers</strong></h3>
<p>by Tanmay Bakshi, Baheer Kamal</p>
<p>Released May 2021</p>
<p>ISBN: 9781264258154</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/tanmay-teaches-go/9781264258154/">https://www.oreilly.com/library/view/tanmay-teaches-go/9781264258154/</a></p>
<h3 id="heading-building-microservices-with-go"><strong>Building Microservices with Go</strong></h3>
<p>by Nic Jackson</p>
<p>Released July 2017</p>
<p>ISBN: 9781786468666</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/building-microservices-with/9781786468666/">https://www.oreilly.com/library/view/building-microservices-with/9781786468666/</a></p>
<h3 id="heading-distributed-services-with-go"><strong>Distributed Services with Go</strong></h3>
<p>by Travis Jeffery</p>
<p>Released March 2021</p>
<p>ISBN: 9781680507607</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/distributed-services-with/9781680508376/">https://www.oreilly.com/library/view/distributed-services-with/9781680508376/</a></p>
<h3 id="heading-go-brain-teasers"><strong>Go Brain Teasers</strong></h3>
<p>by Miki Tebeka</p>
<p>Released August 2021</p>
<p>ISBN: 9781680508994</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-brain-teasers/9781680509144">https://www.oreilly.com/library/view/go-brain-teasers/9781680509144</a></p>
<h3 id="heading-go-design-patterns"><strong>Go Design Patterns</strong></h3>
<p>by Mario Castro Contreras</p>
<p>Released February 2017</p>
<p>ISBN: 9781786466204</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-design-patterns/9781786466204/">https://www.oreilly.com/library/view/go-design-patterns/9781786466204/</a></p>
<h3 id="heading-security-with-go"><strong>Security with Go</strong></h3>
<p>by John Daniel Leon</p>
<p>Released January 2018</p>
<p>ISBN: 9781788627917</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/security-with-go/9781788627917/">https://www.oreilly.com/library/view/security-with-go/9781788627917/</a></p>
<h3 id="heading-hands-on-serverless-applications-with-go"><strong>Hands-On Serverless Applications with Go</strong></h3>
<p>by Mohamed Labouardy</p>
<p>Released August 2018</p>
<p>ISBN: 9781789134612</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-serverless-applications/9781789134612/">https://www.oreilly.com/library/view/hands-on-serverless-applications/9781789134612/</a></p>
<h3 id="heading-cloud-native-programming-with-golang"><strong>Cloud Native programming with Golang</strong></h3>
<p>by Mina Andrawos, Martin Helmich</p>
<p>Released December 2017</p>
<p>ISBN: 9781787125988</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/cloud-native-programming/9781787125988/">https://www.oreilly.com/library/view/cloud-native-programming/9781787125988/</a></p>
<h3 id="heading-go-design-patterns-for-real-world-projects"><strong>Go: Design Patterns for Real-World Projects</strong></h3>
<p>by Vladimir Vivien, Mario Castro Contreras, Mat Ryer</p>
<p>Released June 2017</p>
<p>ISBN: 9781788390552</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-design-patterns/9781788390552/">https://www.oreilly.com/library/view/go-design-patterns/9781788390552/</a></p>
<h3 id="heading-learn-data-structures-and-algorithms-with-golang"><strong>Learn Data Structures and Algorithms with Golang</strong></h3>
<p>by Bhagvan Kommadi</p>
<p>Released March 2019</p>
<p>ISBN: 9781789618501</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/learn-data-structures/9781789618501/">https://www.oreilly.com/library/view/learn-data-structures/9781789618501/</a></p>
<h3 id="heading-programming-in-go-creating-applications-for-the-21st-century"><strong>Programming in Go: Creating Applications for the 21st Century</strong></h3>
<p>by Mark Summerfield</p>
<p>Released May 2012</p>
<p>ISBN: 9780132764094</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/programming-in-go/9780132764100/">https://www.oreilly.com/library/view/programming-in-go/9780132764100/</a></p>
<h3 id="heading-hands-on-software-architecture-with-golang"><strong>Hands-On Software Architecture with Golang</strong></h3>
<p>by Jyotiswarup Raiturkar</p>
<p>Released December 2018</p>
<p>ISBN: 9781788622592</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-software-architecture/9781788622592/">https://www.oreilly.com/library/view/hands-on-software-architecture/9781788622592/</a></p>
<h3 id="heading-level-up-your-web-apps-with-go"><strong>Level Up Your Web Apps With Go</strong></h3>
<p>By Mal Curtis</p>
<p>Released April 2015</p>
<p>ISBN: 9780992461294</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/level-up-your/9781457192845/">https://www.oreilly.com/library/view/level-up-your/9781457192845/</a></p>
<h3 id="heading-100-go-mistakes-and-how-to-avoid-them"><strong>100 Go Mistakes and How to Avoid Them</strong></h3>
<p>by Teiva Harsanyi</p>
<p>Released September 2022</p>
<p>ISBN: 9781617299599</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/100-go-mistakes/9781617299599">https://www.oreilly.com/library/view/100-go-mistakes/9781617299599</a></p>
<h3 id="heading-hands-on-deep-learning-with-go"><strong>Hands-On Deep Learning with Go</strong></h3>
<p>by Gareth Seneque, Darrell Chua</p>
<p>Released August 2019</p>
<p>ISBN: 9781789340990</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-deep-learning/9781789340990/">https://www.oreilly.com/library/view/hands-on-deep-learning/9781789340990/</a></p>
<h3 id="heading-go-web-scraping-quick-start-guide"><strong>Go Web Scraping Quick Start Guide</strong></h3>
<p>by Vincent Smith</p>
<p>Released January 2019</p>
<p>ISBN: 9781789615708</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-web-scraping/9781789615708/">https://www.oreilly.com/library/view/go-web-scraping/9781789615708/</a></p>
<h3 id="heading-learning-functional-programming-in-go"><strong>Learning Functional Programming in Go</strong></h3>
<p>by Lex Sheehan</p>
<p>Released November 2017</p>
<p>ISBN: 9781787281394</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/learning-functional-programming/9781787281394/">https://www.oreilly.com/library/view/learning-functional-programming/9781787281394/</a></p>
<h3 id="heading-hands-on-gui-application-development-in-go"><strong>Hands-On GUI Application Development in Go</strong></h3>
<p>by Andrew Williams</p>
<p>Released February 2019</p>
<p>ISBN: 9781789138412</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-gui-application/9781789138412/">https://www.oreilly.com/library/view/hands-on-gui-application/9781789138412/</a></p>
<h3 id="heading-go-machine-learning-projects"><strong>Go Machine Learning Projects</strong></h3>
<p>by Xuanyi Chew</p>
<p>Released November 2018</p>
<p>ISBN: 9781788993401</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-machine-learning/9781788993401/">https://www.oreilly.com/library/view/go-machine-learning/9781788993401/</a></p>
<h3 id="heading-go-for-devops"><strong>Go for DevOps</strong></h3>
<p>by John Doak, David Justice</p>
<p>Released July 2022</p>
<p>ISBN: 9781801818896</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/go-for-devops/9781801818896/">https://www.oreilly.com/library/view/go-for-devops/9781801818896/</a></p>
<h3 id="heading-hands-on-software-architecture-with-golang"><strong>Hands-On Software Architecture with Golang</strong></h3>
<p>by Jyotiswarup Raiturkar</p>
<p>Released December 2018</p>
<p>ISBN: 9781788622592</p>
<p><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-software-architecture/9781788622592/">https://www.oreilly.com/library/view/hands-on-software-architecture/9781788622592/</a></p>
]]></content:encoded></item><item><title><![CDATA[Golang: FilePath]]></title><description><![CDATA[Path join in Golang
Manipulating filename paths in a way that is compatible with the any target operating system-defined file paths.
Path joining
When you start changing directories, you have to work with both forward slash and backward slash, depend...]]></description><link>https://go.mohamedallam.tech/golang-filepath</link><guid isPermaLink="true">https://go.mohamedallam.tech/golang-filepath</guid><category><![CDATA[General Programming]]></category><category><![CDATA[Go Language]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Fri, 18 Nov 2022 21:49:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1668808121262/ZSMxD1IwP.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-path-join-in-golang">Path join in Golang</h1>
<p>Manipulating filename paths in a way that is compatible with the any target operating system-defined file paths.</p>
<h2 id="heading-path-joining">Path joining</h2>
<p>When you start changing directories, you have to work with both forward slash and backward slash, depending on the operating system, Unix or Windows, Go takes care of that using <a target="_blank" href="https://pkg.go.dev/path/filepath#Join">path.FilePath.Join function,</a> to use Join, you have to provide the name of the folders, and Go will use the appropriate slash for you</p>
<pre><code class="lang-go"><span class="hljs-comment">// https://pkg.go.dev/path/filepath#Join</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Join</span><span class="hljs-params">(elem ...<span class="hljs-keyword">string</span>)</span> <span class="hljs-title">string</span></span> {
...
}
</code></pre>
<blockquote>
<p>Join joins any number of path elements into a single path, separating them with an OS specific Separator. Empty elements are ignored. The result is Cleaned. However, if the argument list is empty or all its elements are empty, Join returns an empty string. On Windows, the result will only be a UNC path if the first non-empty element is a UNC path.</p>
</blockquote>
<p>To use that, let's change directory using Go.</p>
<h2 id="heading-change-directory-cd">Change directory <code>cd</code></h2>
<p>And also we generally you would need to use the <code>[chdir](https://pkg.go.dev/os#Chdir)</code> you specify the name of the directory you want to go to, and this function would change the current directory for you</p>
<pre><code class="lang-go"><span class="hljs-comment">// https://pkg.go.dev/os#Chdir</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Chdir</span><span class="hljs-params">(dir <span class="hljs-keyword">string</span>)</span> <span class="hljs-title">error</span></span> {
...
}
</code></pre>
<blockquote>
<p>Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.</p>
</blockquote>
<p>Lets combine this two, which does allow us to work with either windows or linux who use / or \ backslash and forward slash for each system, and change directory to for now the names we pass in the <code>ChangeDir</code></p>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">ChangeDir</span><span class="hljs-params">(elem ...<span class="hljs-keyword">string</span>)</span></span> {
    path := filepath.Join(<span class="hljs-string">"./"</span>, filepath.Join(elem...))

    err := os.Chdir(path)
    <span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
        fmt.Println(<span class="hljs-string">"Cant change the workig directory"</span>, err)
    }
}
</code></pre>
<h2 id="heading-joining-strings">Joining strings</h2>
<p>On the same note, if for whatever reason you want to join folder names, based on something different, or if is any strings joined, there is in the Go standard package, a string package that has a <a target="_blank" href="https://pkg.go.dev/strings#Join">join</a> method that is as below</p>
<pre><code class="lang-go">https:<span class="hljs-comment">//pkg.go.dev/strings#Join</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Join</span><span class="hljs-params">(elems []<span class="hljs-keyword">string</span>, sep <span class="hljs-keyword">string</span>)</span> <span class="hljs-title">string</span></span>
</code></pre>
<blockquote>
<p>Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.</p>
</blockquote>
<p>And as the official documentation:</p>
<pre><code class="lang-go">s := []<span class="hljs-keyword">string</span>{<span class="hljs-string">"foo"</span>, <span class="hljs-string">"bar"</span>, <span class="hljs-string">"baz"</span>}
fmt.Println(strings.Join(s, <span class="hljs-string">", "</span>))
<span class="hljs-comment">//Output</span>
<span class="hljs-comment">//foo, bar, baz</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Golang: Jump search algorithm (jump your Go skills)]]></title><description><![CDATA[Search algorithms
Whenever you search an element in an array, you have bunch of choices to reduce the time space and memory space, this optimizations add up, and its referred to as a technology, like if you have some extra RAM storage.
Jump search
On...]]></description><link>https://go.mohamedallam.tech/golang-jump-search-algorithm-jump-your-go-skills</link><guid isPermaLink="true">https://go.mohamedallam.tech/golang-jump-search-algorithm-jump-your-go-skills</guid><category><![CDATA[Go Language]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[golang]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Thu, 08 Sep 2022 11:38:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1662636934711/yJG82DmBs.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-search-algorithms">Search algorithms</h2>
<p>Whenever you search an element in an array, you have bunch of choices to reduce the time space and memory space, this optimizations add up, and its referred to as a technology, like if you have some extra RAM storage.</p>
<h2 id="heading-jump-search">Jump search</h2>
<p>One common technique you might use, is the jump search
Where you search, each foot equals the root of number of elements, so in an array of 100 your jump is 10, in an array of 10000 the jump is 100.
Then once you have crossed the desired value, you go back between the last step and this one.
And iterate though a much smaller array.</p>
<pre><code class="lang-go">
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">TwoCrystalBalls</span><span class="hljs-params">(array []<span class="hljs-keyword">int</span>, target <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    step := <span class="hljs-keyword">int</span>(math.Round(math.Sqrt(<span class="hljs-keyword">float64</span>(<span class="hljs-built_in">len</span>(array)))))
    rbound := <span class="hljs-built_in">len</span>(array)
    <span class="hljs-keyword">for</span> i := step; i &lt; <span class="hljs-built_in">len</span>(array); i += step {
        <span class="hljs-keyword">if</span> array[i] &gt; target {
            rbound = i
            <span class="hljs-keyword">break</span>
        }
    }

    <span class="hljs-keyword">for</span> i := rbound - step; i &lt; rbound; i++ {
        <span class="hljs-keyword">if</span> array[i] == target {
            <span class="hljs-keyword">return</span> array[i]
        }
        <span class="hljs-keyword">if</span> array[i] &gt; target {
            <span class="hljs-keyword">break</span>
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">JumpBinarySearch</span><span class="hljs-params">(array []<span class="hljs-keyword">int</span>, target <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    step := <span class="hljs-keyword">int</span>(math.Round(math.Sqrt(<span class="hljs-keyword">float64</span>(<span class="hljs-built_in">len</span>(array)))))
    <span class="hljs-keyword">var</span> high <span class="hljs-keyword">int</span>
    <span class="hljs-keyword">for</span> i := step; i &lt; <span class="hljs-built_in">len</span>(array); i += step {
        <span class="hljs-keyword">if</span> array[i] &gt; target {
            high = i
            <span class="hljs-keyword">break</span>
        }
    }
    low := high - step
    <span class="hljs-keyword">for</span> low &lt; high {
        mid := low + ((high - low) / <span class="hljs-number">2</span>)
        val := array[mid]
        <span class="hljs-keyword">if</span> val == target {
            <span class="hljs-keyword">return</span> val
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> val &lt; target {
            low = mid + <span class="hljs-number">1</span>
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> val &gt; target {
            high = mid
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>
}
</code></pre>
<h2 id="heading-jump-search-andamp-binary-search">Jump search &amp; binary search</h2>
<p>Binary search can be combined with jump search where in the last step, you instead use the binary search, which will make your algorithm even faster. as shown in the example</p>
]]></content:encoded></item><item><title><![CDATA[Binary Search in Golang and  Linear search method]]></title><description><![CDATA[Algorithms in Golang
Algorithms and data structure is a big portion of our code, and starting out you might come across Binary Search as one of your lessons, If you are into Go, consider this code, as it helps you solve this common question.
Calculat...]]></description><link>https://go.mohamedallam.tech/binary-search-in-golang-and-linear-search-method</link><guid isPermaLink="true">https://go.mohamedallam.tech/binary-search-in-golang-and-linear-search-method</guid><category><![CDATA[golang]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[data structures]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Tue, 06 Sep 2022 22:19:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1662503203247/JUl2D-IVK.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-algorithms-in-golang">Algorithms in Golang</h2>
<p>Algorithms and data structure is a big portion of our code, and starting out you might come across <strong>Binary Search</strong> as one of your lessons, If you are into Go, consider this code, as it helps you solve this common question.</p>
<h2 id="heading-calculating-mid-in-binary-search">Calculating mid in binary search</h2>
<p>Most cases when you write a binary search you make the mistake of using <code>(low + high )/ 2</code> and while this is valid for uint, unsigned integers (0, 255), you may in certain cases, run to a integers (-128, 127) where you run to some weird issues, this code will demonstrate that for you</p>
<pre><code class="lang-Go">
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {

    <span class="hljs-keyword">var</span> low <span class="hljs-keyword">int8</span> = <span class="hljs-number">80</span>
    <span class="hljs-keyword">var</span> high <span class="hljs-keyword">int8</span> = <span class="hljs-number">120</span>
    <span class="hljs-keyword">var</span> mid <span class="hljs-keyword">int8</span>

    mid = (low + (high-low)/<span class="hljs-number">2</span>)
    fmt.Println(mid)
    mid = (high + low) / <span class="hljs-number">2</span>
    fmt.Println(mid)
}
</code></pre>
<p>Console prints out:</p>
<blockquote>
<p>100</p>
<p>-28</p>
</blockquote>
<p><a target="_blank" href="https://go.dev/play/p/h7HJxpTP-BV"><strong>try it out</strong></a></p>
<p>If you need more informations, No one is better than <a target="_blank" href="https://en.wikipedia.org/wiki/Joshua_Bloch">Joshua Bloch</a> article, at <a target="_blank" href="https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html">Google blog</a></p>
<p><a target="_blank" href="https://gist.github.com/mohamedallam1991/53ed09e20ec19bcb3aa4e036c3f35d3a">Binary Search in Golang and Linear Search method</a></p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    b := []<span class="hljs-keyword">int</span>{<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">7</span>, <span class="hljs-number">11</span>, <span class="hljs-number">13</span>, <span class="hljs-number">17</span>, <span class="hljs-number">19</span>, <span class="hljs-number">23</span>, <span class="hljs-number">29</span>, <span class="hljs-number">31</span>, <span class="hljs-number">37</span>, <span class="hljs-number">41</span>, <span class="hljs-number">43</span>, <span class="hljs-number">47</span>, <span class="hljs-number">53</span>, <span class="hljs-number">59</span>, <span class="hljs-number">61</span>, <span class="hljs-number">67</span>, <span class="hljs-number">71</span>, <span class="hljs-number">73</span>, <span class="hljs-number">79</span>, <span class="hljs-number">83</span>, <span class="hljs-number">89</span>, <span class="hljs-number">97</span>, <span class="hljs-number">100</span>, <span class="hljs-number">159</span>, <span class="hljs-number">192</span>, <span class="hljs-number">350</span>, <span class="hljs-number">1230</span>, <span class="hljs-number">1341</span>, <span class="hljs-number">4533</span>}

    fmt.Println(BinarySearch(b, <span class="hljs-number">31</span>))
    fmt.Println(LinearSearch(b, <span class="hljs-number">31</span>))

}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">BinarySearch</span><span class="hljs-params">(haystack []<span class="hljs-keyword">int</span>, needle <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">bool</span></span> {
    <span class="hljs-keyword">var</span> high, low, mid, val <span class="hljs-keyword">int</span>
    low = <span class="hljs-number">0</span>
    high = <span class="hljs-built_in">len</span>(haystack)
    <span class="hljs-keyword">for</span> low &lt; high {
        mid = (low + ((high - low) / <span class="hljs-number">2</span>))
        val = haystack[mid]
        fmt.Println(val)
        <span class="hljs-keyword">if</span> val == needle {
            <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> val &gt; needle {
            high = mid
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> val &lt; needle {
            low = mid + <span class="hljs-number">1</span>
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">LinearSearch</span><span class="hljs-params">(haystack []<span class="hljs-keyword">int</span>, needle <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">bool</span></span> {
    <span class="hljs-keyword">for</span> _, v := <span class="hljs-keyword">range</span> haystack {
        fmt.Println(v)
        <span class="hljs-keyword">if</span> v == needle {
            <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Multiplication & addition tables to print out]]></title><description><![CDATA[This is how you print out the multiplication and addition tables in Golang.

func Multiply() {
    for i := 1; i < 10; i++ {
        fmt.Printf("Multiplication table: %v\n", i)
        for j := 1; j < 10; j++ {
            a := j * i
            fmt....]]></description><link>https://go.mohamedallam.tech/multiplication-addition-tables-to-print-out</link><guid isPermaLink="true">https://go.mohamedallam.tech/multiplication-addition-tables-to-print-out</guid><category><![CDATA[Go Language]]></category><category><![CDATA[golang]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[data structures]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Mon, 05 Sep 2022 12:14:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/4ApmfdVo32Q/upload/v1662379928434/ndcRLvqn4.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is how you print out the multiplication and addition tables in Golang.</p>
<pre><code class="lang-go">
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Multiply</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">for</span> i := <span class="hljs-number">1</span>; i &lt; <span class="hljs-number">10</span>; i++ {
        fmt.Printf(<span class="hljs-string">"Multiplication table: %v\n"</span>, i)
        <span class="hljs-keyword">for</span> j := <span class="hljs-number">1</span>; j &lt; <span class="hljs-number">10</span>; j++ {
            a := j * i
            fmt.Printf(<span class="hljs-string">"%v * %v = %v\n"</span>, i, j, a)
        }
    }
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Additioning</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">11</span>; i++ {
        fmt.Printf(<span class="hljs-string">"Additioning table: %v\n"</span>, i)
        <span class="hljs-keyword">for</span> j := <span class="hljs-number">0</span>; j &lt; <span class="hljs-number">10</span>; j += <span class="hljs-number">1</span> {
            a := j + i
            fmt.Printf(<span class="hljs-string">"%v + %v = %v\n"</span>, i, j, a)
        }
    }
}
</code></pre>
<p>You can do something like this to use it</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span>{
  Additioning()
  Multiply()
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Golang bad file descriptor (how to append to a file in Go)]]></title><description><![CDATA[Golang updating a file
When you use Golang, Its really a good idea, playing with files is actually fun, however this popular error, occurs when you want to update or append to a file, without deleteing the text written already.
Golang creating a file...]]></description><link>https://go.mohamedallam.tech/golang-bad-file-descriptor-how-to-append-to-a-file-in-go</link><guid isPermaLink="true">https://go.mohamedallam.tech/golang-bad-file-descriptor-how-to-append-to-a-file-in-go</guid><category><![CDATA[Go Language]]></category><category><![CDATA[golang]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Mohamed Allam]]></dc:creator><pubDate>Thu, 01 Sep 2022 20:55:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/bSlHKWxxXak/upload/v1662380205378/TarLThxRr.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-golang-updating-a-file">Golang updating a file</h2>
<p>When you use Golang, Its really a good idea, playing with files is actually fun, however this popular error, occurs when you want to update or append to a file, without deleteing the text written already.</p>
<h2 id="heading-golang-creating-a-file">Golang creating a file</h2>
<p>This is only possible if you want to write to the file for the first time.</p>
<pre><code class="lang-go">f, err := os.Create(fileName)
<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
    <span class="hljs-keyword">return</span> err
}
_, err = f.WriteString(<span class="hljs-string">"text"</span>)
<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
    <span class="hljs-keyword">return</span> err
}
</code></pre>
<h2 id="heading-golang-updating-a-file">Golang updating a file</h2>
<p>This is how you open a file, and append to it.</p>
<pre><code class="lang-go">f, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm)
<span class="hljs-comment">// the args: os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm</span>
<span class="hljs-comment">//f, err := os.Create(fileName)</span>
<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
    <span class="hljs-keyword">return</span> err
}
_, err = f.WriteString(<span class="hljs-string">"text"</span>)
<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
    <span class="hljs-keyword">return</span> err
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1662064116961/wdSC-lluW.png" alt="bad-file-descriptor.png" /></p>
<p>for more inforamtions please referr to <a target="_blank" href="https://stackoverflow.com/questions/33851692/golang-bad-file-descriptor">this stackoverflow link</a>.</p>
]]></content:encoded></item></channel></rss>