<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Frihk Ian</title>
    <description>The latest articles on DEV Community by Frihk Ian (@frihk_ian).</description>
    <link>https://dev.to/frihk_ian</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3722900%2Feb25e3b9-2480-4724-b76b-377729624660.png</url>
      <title>DEV Community: Frihk Ian</title>
      <link>https://dev.to/frihk_ian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frihk_ian"/>
    <language>en</language>
    <item>
      <title>Data Types In Go</title>
      <dc:creator>Frihk Ian</dc:creator>
      <pubDate>Tue, 14 Apr 2026 08:23:50 +0000</pubDate>
      <link>https://dev.to/frihk_ian/data-types-in-go-5fm3</link>
      <guid>https://dev.to/frihk_ian/data-types-in-go-5fm3</guid>
      <description>&lt;p&gt;This is the first in a series of articles exploring data types in Go. The main goal of this series of articles is to provide detailed explanations and practical examples to help you build a clear and strong understanding of the different data types in Go. All the topics will be subdivided into manageable sections, each focusing on a specific aspect of data types, to facilitate gradual learning.&lt;/p&gt;

&lt;p&gt;There are many different data types in Go:&lt;br&gt;
The two main data types include:&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Basic(primitive) Types
&lt;/h2&gt;

&lt;p&gt;This type of data is made up of :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numbers(int, float64)&lt;/li&gt;
&lt;li&gt;Strings(string)&lt;/li&gt;
&lt;li&gt;Boolean(bool)&lt;/li&gt;
&lt;li&gt;Composite Types&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  2. Composite Types
&lt;/h2&gt;

&lt;p&gt;These include &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Slices&lt;/li&gt;
&lt;li&gt;Maps&lt;/li&gt;
&lt;li&gt;Structs&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Other Important Types
&lt;/h2&gt;

&lt;p&gt;These are other very powerful and commonly used data types.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function types (functions are treated as values)&lt;/li&gt;
&lt;li&gt;Pointer Types (used to work with memory)&lt;/li&gt;
&lt;li&gt;Interfaces Types(used to define a certain behavior and simplifying flexibility)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, I will focus on basic data types, as they are fundamental to understanding Go and provide a solid foundation for more complex types. While the other types, such as composite, are not necessarily difficult, they involve broader concepts and all depend on the basic types. For a better understanding of each, I cover each in greater depth in separate, dedicated articles.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic(primitive) Types
&lt;/h2&gt;

&lt;p&gt;Let's delve directly into the details:&lt;/p&gt;
&lt;h3&gt;
  
  
  Numbers.
&lt;/h3&gt;

&lt;p&gt;Numbers are divided into : &lt;/p&gt;
&lt;h4&gt;
  
  
  Integers
&lt;/h4&gt;

&lt;p&gt;These are whole numbers. In  Go, we use them in two main ways :&lt;br&gt;
&lt;strong&gt;Int&lt;/strong&gt; - This is the most commonly used, including both positive and negative whole numbers.&lt;br&gt;
&lt;strong&gt;Uint&lt;/strong&gt; - Used to represent only positive whole numbers.&lt;/p&gt;
&lt;h4&gt;
  
  
  Floating-point
&lt;/h4&gt;

&lt;p&gt;These are real numbers (numbers with decimal points). They include both positive and negative numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;25&lt;/span&gt; &lt;span class="c"&gt;// 25 is an integer &lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="kt"&gt;float32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;186.8&lt;/span&gt; &lt;span class="c"&gt;// 186.8 is a float &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Go, Floating-point can either be float32 or float64. The choice lies in the level of precision you need.&lt;/p&gt;

&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;In Go, strings are immutable sequences of UTF-8 encoded bytes, meaning once created, they cannot be altered, which ensures data integrity and consistency.&lt;/p&gt;

&lt;h4&gt;
  
  
  Immutability
&lt;/h4&gt;

&lt;p&gt;Once a string is created, it cannot be changed. Any attempt to change it creates a new string. &lt;/p&gt;

&lt;h4&gt;
  
  
  Indexing
&lt;/h4&gt;

&lt;p&gt;The individual bytes can be accessed with a given index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c"&gt;// 72 (byte value of 'H')&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print 72 as the strings store bytes and H is equal to the ASCII (byte) code of 72.&lt;/p&gt;

&lt;h4&gt;
  
  
  Length
&lt;/h4&gt;

&lt;p&gt;The number of bytes, not characters, is returned by the len() function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Unicode and Runes
&lt;/h4&gt;

&lt;p&gt;As the strings are UTF-8, some characters can occupy more than one byte. to act on characters (runes), use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output&lt;br&gt;
&lt;code&gt;72&lt;br&gt;
101&lt;br&gt;
108&lt;br&gt;
108&lt;br&gt;
111&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  String Concatenation
&lt;/h4&gt;

&lt;p&gt;The + operator can be used to add strings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;full&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"World"&lt;/span&gt;  &lt;span class="c"&gt;// Hello World&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Byte Slice. &lt;br&gt;
You can convert a string to a slice of bytes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Boolean
&lt;/h3&gt;

&lt;p&gt;In Go, boolean values represent truth values; they can only be written as either true or false. They are used mostly for comparison purposes and control a program flow in if, for, or switch statements. In Go, by default, an uninitialized boolean has the value false, making it predictable and easy to work with in decision-making logic.&lt;/p&gt;

&lt;p&gt;The section has links to the data types used so far. A link to the next article will be added once it’s ready. When a link is not given on a given type of data, simply means that it is still in the process and it will be given shortly.&lt;br&gt;
&lt;a href="https://dev.to/frihk_ian/maps-in-golang-4jif"&gt;Maps&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Additional learning materials.&lt;br&gt;
&lt;a href="https://go.dev/tour/basics/11" rel="noopener noreferrer"&gt;Go Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/go/go_data_types.php" rel="noopener noreferrer"&gt;W3schools&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>go</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Maps in Golang</title>
      <dc:creator>Frihk Ian</dc:creator>
      <pubDate>Tue, 10 Mar 2026 07:23:29 +0000</pubDate>
      <link>https://dev.to/frihk_ian/maps-in-golang-4jif</link>
      <guid>https://dev.to/frihk_ian/maps-in-golang-4jif</guid>
      <description>&lt;p&gt;Maps are one of the most flexible data types in Go. It might even be the most flexible compared to maps from other programming languages. And just as flexible as they are , they are also as simple to initialize.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Map Structure&lt;/strong&gt;&lt;br&gt;
A map in Go is composed of two main parts: the key and the value. The key is defined as a unique label used to store and find a specific &lt;br&gt;
Maps are one of the main data structures in Go. Maps have two main parts : the key and the value. The key is like a word you are looking up in a dictionary. It is a unique label that stores and carries a specific type of data. Whilst the value is like the definition of the word you are looking up in a dictionary, it is the data that is stored in the key value. Unlike keys, which only accept comparable types, the value can be of any legal Go type.&lt;/p&gt;

&lt;p&gt;In Go, there are two main ways to initialize maps. The first uses the Go built-in make function:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;m := make(map[string]int)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The second one uses a map literal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;m := map[string]int{}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;They initialize an empty map that takes in a string as the key and an integer as the value. The make method is more flexible because it allows you to specify an initial capacity. When the expected size is known, this preallocation can reduce map growth and rehashing during execution.&lt;/p&gt;

&lt;p&gt;Accessing Values and Handling Missing Keys&lt;br&gt;
Reading from a map in Go is quite simple. You access a value by indexing the map with its key, as shown below:&lt;br&gt;
&lt;code&gt;age := m["John"]&lt;/code&gt;&lt;br&gt;
Sometimes you might call a key that is not in the map; this happens as a result of misspelling or during testing. Go does not display any error, nor does it crash. It instead displays the zero value of the map's value type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"missing_key"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// value is 0&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program above displays:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The “Comma ok” Idiom&lt;/strong&gt;&lt;br&gt;
This can be misleading; if a key has a value of zero, it becomes difficult to know whether the key has a zero value or its value is a zero. Go handles this by introducing the “ok” to help solve this error. This helps distinguish the erroneous value and the correct value.&lt;/p&gt;

&lt;p&gt;value, ok := m["missing_key"]&lt;br&gt;
if !ok {&lt;br&gt;
    Return “Error” // The key does not exist in the map&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Here, the value is the data in the map value. Whilst the “ok” is a boolean that is true. If the value exist then the ok becomes true, and the program executes without any error. If it does not exist, then the program returns an “error.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inserting and Updating Data&lt;/strong&gt;&lt;br&gt;
In Go, the syntax for inserting, updating, or deleting data in a map is consistent and straightforward. When adding/ updating a key, you simply assign a value; the method is pretty much the same as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// Insert: Key "Alice" does not exist, so it is created.&lt;/span&gt;
&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;25&lt;/span&gt; 

&lt;span class="c"&gt;// Update: Key "Alice" already exists, so its value is overwritten.&lt;/span&gt;
&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;26&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deleting Elements&lt;/strong&gt;&lt;br&gt;
When deleting from a map, we use the Go built-in function delete(). It removes the key and everything associated with it. Below is its syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Removes "Alice" from the map&lt;/span&gt;
&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The delete function has a safety feature that makes it very safe to work with. In case of deletion of something that is not in the map, it simply does nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iterating Over Maps&lt;/strong&gt;&lt;br&gt;
Now that you know how to add and remove individual items, you’ll likely want to loop through the entire collection. In Go, we use the range keyword to iterate over a map.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Alice&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Bob&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Charlie&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;35&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Something to keep in mind when it comes to maps is that they are  “commitment-phobic” when it comes to order. Unlike arrays or slices, they do not have a specified order during iteration. If you run the code above three times, chances are that you might get three different sequences. If you need a consistent order, you’ll have to sort the keys manually in a separate slice first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Maps as Reference Types&lt;/strong&gt;&lt;br&gt;
The most significant points to keep in mind are that maps are a type of reference. Passing a map to a function does not give a copy of the data, but the pointer to the underlying data structure.&lt;br&gt;
This implies that when you make changes to a map within a function, the changes will be carried over to the original map.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;updateAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Alice&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt; &lt;span class="c"&gt;// This changes the original map!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Map Performance and Concurrency&lt;/strong&gt;&lt;br&gt;
Maps are incredibly fast, offering O(1) average time complexity for searches, additions, and deletions. Maps are extremely quick with an average time complexity of O(1) for searches, add, and delete. There is, however, a kind of safety limit that they have: Maps are not thread-safe.&lt;br&gt;
If two different goroutines try to write to the same map at the same time, your program will crash with a fatal error: concurrent map writes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature 
Behavior in Golang Maps
Search Speed
Extremely fast (Constant time)
Iteration Order
Random/Unordered
Thread Safety
None (Requires sync.Mutex or sync.Map)
Zero Value
nil (A nil map can be read, but writing to it causes a panic)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Maps are the go-to tool in Go when you need a fast, associative data structure. By mastering the make function, the “comma ok” idiom, and understanding the nuances of iteration and reference types, you can handle complex data relationships with very little code.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>go</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Go templates</title>
      <dc:creator>Frihk Ian</dc:creator>
      <pubDate>Wed, 11 Feb 2026 12:23:08 +0000</pubDate>
      <link>https://dev.to/frihk_ian/go-templates-51nm</link>
      <guid>https://dev.to/frihk_ian/go-templates-51nm</guid>
      <description>&lt;p&gt;The first thing to handle is answering the question, "what are Go templates?" Go templates are a way to create dynamic content in Go by allowing the user to mix data with plain text or HTML files with data received from the Go code. This makes it possible to change the data in a template very easily, as it can be edited with ease. They are mainly used in web dev to create web pages that rely on user inputs or content from a database.&lt;br&gt;
A template is just a file that has placeholders for data. In Go, placeholders are written using double curly braces {{ }}. These curly braces can hold a user’s data, and this can be shown by {{ .name }}. The dot refers to the data object you refer to from Go. When the template is running, Go replaces the {{ .name }} with the actual user name from the user's input or the database.&lt;br&gt;
To use templates in Go, a data structure that can help you hold the data to show, usually a map or a struct, is required.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type PageData struct {
    Title   string
    Message string
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you parse the template file in your Go code and execute it with your data. The template system will automatically replace all placeholders with the correct values. This keeps your HTML or text separate from your Go code, making your program cleaner and easier to maintain.&lt;br&gt;
A good example of template file is as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;{{ .Title }}&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;{{ .Title }}&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;{{ .Message }}&amp;lt;/p&amp;gt;

    {{ if .IsLogged }}
        &amp;lt;p&amp;gt;Welcome back, {{ .User }}! &amp;lt;/p&amp;gt;
    {{ else }}
        &amp;lt;p&amp;gt;Please login to continue. &amp;lt;/p&amp;gt;
    {{ end }}

    &amp;lt;h2&amp;gt;Your Tasks:&amp;lt;/h2&amp;gt;
    &amp;lt;ul&amp;gt;
        {{ range .Tasks }}
            &amp;lt;li&amp;gt;{{ . }}&amp;lt;/li&amp;gt;
        {{ else }}
            &amp;lt;li&amp;gt;No tasks available.&amp;lt;/li&amp;gt;
        {{ end }}
    &amp;lt;/ul&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go templates also support basic logic. This helps to manipulate the values to be displayed. You can display certain things if a certain condition is met. You can also range over maps, structs, among others. For example, you can display a specific message to only logged-in users, you can list all the content of a check list from a shopping list among many others. You can also use functions like len to make the content more flexible.&lt;br&gt;
Below is an example of Go code that displays its output to the HTML file above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "html/template"
    "net/http"
)

type PageData struct {
    Title    string
    Message  string
    IsLogged bool
    User     string
    Tasks    []string
}

func handler(w http.ResponseWriter, r *http.Request) {
    data := PageData{
        Title:    "Go Templates Advanced Example",
        Message:  "Using conditions and loops in templates",
        IsLogged: true,
        User:     "Ian",
        Tasks:    []string{"Learn Go templates", "Build a web app", "Practice Go daily"},
    }

    tmpl := template.Must(template.ParseFiles("index.html"))
    tmpl.Execute(w, data)
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In summary, to generate a dynamic text or HTML in Go, the best option is the Go template. They help separate the design of your output from your code logic, allow you to reuse templates with different data, and make it easy to build web pages, reports, or any text-based content.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>go</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
