<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmadreza Marashi on Medium]]></title>
        <description><![CDATA[Stories by Ahmadreza Marashi on Medium]]></description>
        <link>https://medium.com/@ahmad1997rezamarashi?source=rss-142fefa13f1e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_Hw89cvLXbtZtZzAITmU2g.jpeg</url>
            <title>Stories by Ahmadreza Marashi on Medium</title>
            <link>https://medium.com/@ahmad1997rezamarashi?source=rss-142fefa13f1e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:16:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmad1997rezamarashi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reliability Handbook (Chapter 1)]]></title>
            <link>https://medium.com/@ahmad1997rezamarashi/reliability-handbook-chapter-1-646c41244be4?source=rss-142fefa13f1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/646c41244be4</guid>
            <category><![CDATA[reliability]]></category>
            <category><![CDATA[sofware-engineering]]></category>
            <category><![CDATA[incident]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[site-reliability-engineer]]></category>
            <dc:creator><![CDATA[Ahmadreza Marashi]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 16:19:39 GMT</pubDate>
            <atom:updated>2025-01-22T16:22:25.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uRTpYgMG7rROcZpp" /></figure><p>Over the past few months, I’ve been leading an initiative in our team at <a href="https://www.linkedin.com/company/momox/posts/?feedView=all">Momox</a> to define, measure, and enhance system reliability. Through this journey, We’ve gained valuable insights into the principles and practices of reliability, which I’d like to share with you.</p><p>My goal is to provide a clear and practical framework for understanding system reliability, one that you can adapt and apply to your own work.</p><p>This document provides a comprehensive guide to understanding and enhancing the reliability of our services. It addresses the following key topics:</p><ul><li><strong>Chapter 1) Definition of Reliability</strong>: A clear understanding of how reliability is defined within the context of our services and its significance to users.</li><li><strong>Chapter 2) Reliability in Action</strong>: An exploration of common challenges faced in ensuring reliability and how tools like Service Level Indicators (SLIs), Service Level Objectives (SLOs), and Service Level Agreements (SLAs) can help overcome them.</li><li><strong>Chapter 3) Implementing SLOs</strong>: A step-by-step guide to incorporating SLO practices into our services to achieve measurable and actionable reliability improvements.</li><li><strong>Chapter 4) Incidents and Reliability</strong>: Insights into the definition of incidents, their relationship with reliability, and the key metrics in an incident timeline. This section also discusses strategies to mitigate the impact of incidents and maintain service reliability.</li><li><strong>Chapter 5) Monitoring for Reliability</strong>: An examination of effective monitoring objectives, with a focus on identifying critical aspects of our services that should be tracked to ensure consistent reliability.</li></ul><p>This document serves as a practical resource for understanding and applying reliability-focused strategies to our services.</p><h3>1) Definition of Reliability</h3><p>In this chapter, we explore the concept of reliability and identify key properties that define it.</p><p>We begin by distinguishing reliability from commonly confused terms. Next, we examine its role in various software services to establish an initial definition of reliability. Following this, we delve into additional properties contributing to a more comprehensive and refined understanding of the concept.</p><p>By the end of this chapter, readers will understand what reliability means in the context of software services.</p><h3>1.1) What is not Reliability</h3><p>When you think about reliability, what comes to mind? Would you consider any of the following definitions as reliability?</p><ol><li>The ability of a workload to recover from infrastructure or service disruptions.</li><li>The time it takes for a system to respond to a request.</li><li>The degree to which the system provides relevant, accurate results in response to user queries.</li><li>The percentage of time that a system or component is operational and capable of performing its function.</li></ol><p>While these definitions may partially relate to reliability in some contexts, none truly defines reliability. Instead, they represent distinct concepts:</p><ul><li><strong>Resilience</strong> (1): The ability to recover from disruptions.</li><li><strong>Latency</strong> (2): The time taken to respond to a request.</li><li><strong>Correctness</strong> (3): The accuracy and relevance of results.</li><li><strong>Availability</strong> (4): The uptime or operational readiness of a system.</li></ul><p>Although these attributes contribute to a reliable system, they are not synonymous with reliability itself.</p><h3>1.2) What does reliability mean</h3><p>To better understand reliability, let’s examine a few scenarios.</p><p>Example 1: Online Food Delivery Platform</p><p>Imagine you are developing an online food delivery platform. Under what conditions would you consider your service unreliable? Here are some examples:</p><ul><li>Processing transaction requests too slowly.</li><li>Being unavailable for an unacceptable amount of time.</li><li>Losing users’ data after an outage.</li><li>Deducting money from users’ accounts more than once.</li></ul><p>These are scenarios where your application might be considered unreliable.</p><p>Example 2: Movie Recommendation Service</p><p>Now, consider a movie recommendation service. Here are examples of conditions that might make it unreliable:</p><ul><li>Being unavailable for an unacceptable amount of time.</li><li>Showing irrelevant or poorly matched suggestions.</li></ul><p>Key Observations About Reliability</p><p>By looking at these two different examples, we can observe a few key insights about reliability:</p><ol><li><strong>Reliability Has Multiple Dimensions: </strong>Reliability is not just about being fast enough (low latency) or being available; it goes beyond that. It’s about how well your service meets user expectations. For instance, in an online food delivery platform, both speed and availability are crucial, whereas, in a recommendation service, relevancy and availability may matter more.</li><li><strong>Reliability Is the Most Important Feature: </strong>Fancy features lose their value if the core service is unreliable. For example, no one will care about innovative features in a banking app if the service is frequently unavailable or inconsistent.</li><li><strong>The Weight of Reliability Dimensions Varies by Service: </strong>Different dimensions of reliability carry different levels of importance depending on the service. For example:In a recommendation service, showing a suggestion twice may be a minor issue. In an online banking service, deducting money twice is a major problem. Consistency and accuracy are far more critical for online banking than for a recommendation service.</li></ol><blockquote>We can define a system as reliable when: <strong>“It performs well enough from the user’s perspective.”</strong></blockquote><p>It is important to emphasize the word “user” here. For example, high CPU usage alone does not make a service unreliable unless it impacts the user experience. Reliability is ultimately about how well your service performs in dimensions that matter to the user, such as latency, availability, and consistency.</p><h3>1.3) Reliability VS incident</h3><p>When our service is not performing well, it often indicates the occurrence of an incident. (We will explore incidents in greater depth later.) For now, it’s important to note that incidents are typically the root cause of unreliability.</p><h3>1.4) Why 100% Reliability is a Wrong Target</h3><p>It can be tempting to aim for 100% reliability, but it’s important to understand why this goal is neither practical nor desirable:</p><p><strong>Reliability and Change Are Complementary</strong></p><p>As we’ve discussed, reliability and the rate of changes are closely linked. Achieving 100% reliability would require drastically reducing the rate of changes, which is not feasible for most businesses. Continuous updates and improvements are essential for staying competitive, but they inherently introduce some level of risk.</p><p><strong>Customer Experience Is Influenced by External Factors</strong></p><p>Even if your system achieves 100% reliability, your customers won’t necessarily experience it. The end-to-end chain between your system and your customers often involves multiple systems, networks, and intermediaries — any of which can fail. Therefore, absolute reliability within your system doesn’t guarantee a perfect experience for your customers.</p><p><strong>Realistic Limits</strong></p><p>Even with robust redundancy, automated health checks, and fast failover mechanisms, there is always a nonzero probability of simultaneous failures. Unexpected issues can arise, making 100% availability impossible to guarantee.</p><h3>1.5) Summary</h3><p>Key Takeaways from This Chapter:</p><ul><li><strong>Reliability is the most important feature of any service.</strong> It underpins user trust and satisfaction.</li><li>A service is considered <strong>reliable if it performs well from the user’s perspective.</strong> User experience is the ultimate measure of reliability.</li><li>We recognize that <strong>a certain degree of unreliability is acceptable.</strong> This “failure budget” enables teams to innovate, develop, and launch new features without compromising overall system performance.</li></ul><p>In the next chapter, we will explore the challenges of implementing reliability in practice and discuss strategies for addressing them within our teams.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=646c41244be4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding nil in Golang]]></title>
            <link>https://medium.com/@ahmad1997rezamarashi/understanding-nil-df33d1b0fd31?source=rss-142fefa13f1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/df33d1b0fd31</guid>
            <category><![CDATA[nil]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[go-tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ahmadreza Marashi]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 11:35:56 GMT</pubDate>
            <atom:updated>2023-07-02T11:05:41.651Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will explore the concept of nil in Go and answer two questions: What is nil? When do we need to use nil?</p><h3>What is nil?</h3><p>In Go, nil is a predefined identifier that represents the zero value of many types and has no type of its own. It is a keyword that can be used without declaration. It is similar to null in other programming languages.</p><p>For example:</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br>)<br><br>func main() {<br>   nil := &quot;ahmadreza&quot; // it&#39;s not a keyword, you can do it but don&#39;t.<br>   fmt.Println(nil) // ahmadreza<br>}</pre><p>In the above example, we declared a variable named “nil” and assigned it the value “ahmadreza.” This works because “nil” is not a keyword in Go and can be used as a variable name. However, it is not recommended to use “nil” as a variable name because it can lead to confusion.</p><p>A <strong>zero value</strong> is the default value assigned to a variable of a given type if no value is specified. Some common zero values in Go include 0 for integers, false for booleans, “” for strings, and <strong>nil</strong> for <strong>pointers, slices, maps, channels, interfaces</strong>, and <strong>functions</strong>. Understanding zero values is important when initializing variables to ensure that they are not accidentally left in an uninitialized state.</p><p>For example</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br>)<br><br>func main() {<br> var sampleString string<br> var sampleSlice []int<br><br> fmt.Printf(&quot;zero value of string is \&quot;\&quot; %v \n&quot;, sampleString == &quot;&quot;)<br> fmt.Printf(&quot;zero value of slice is nil %v \n&quot;, sampleSlice == nil)<br>}<br>/*<br>zero value of string is &quot;&quot; true <br>zero value of slice is nil true <br>*/</pre><h3>When is nil used?</h3><p>Nil is used in several contexts in Go, including pointers, slices, maps, channels, interfaces, and functions.</p><h3>Pointer</h3><p>A pointer in Go points to a position in memory, and a nil pointer points to nothing. It is represented by the * symbol.</p><p><strong>Pointer receiver with nil</strong></p><p>when you try to access a nil pointer or an invalid memory address, it’ll panic.</p><p><a href="https://go.dev/play/p/73GL3ATPJaB">example</a></p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br>)<br><br>type Person struct {<br> Name string<br>}<br><br>func (p *Person) GetName() string {<br> return p.Name<br>}<br><br>func main() {<br> var p *Person // p is pointer, zero value of p is nil<br> fmt.Println(p.GetName()) // panic: runtime error: invalid memory address or nil pointer dereference<br>}</pre><p>How to fix it?</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br>)<br><br>type Person struct {<br> Name string<br>}<br><br>func (p *Person) GetName() string {<br> if p == nil {<br>  return &quot;empty&quot;<br> }<br> return p.Name<br>}<br><br>func main() {<br> var p *Person            // p is pointer, zero value of p is nil<br> fmt.Println(p.GetName()) // empty<br>}</pre><h4>How to make nil receiver useful</h4><p>chain of Getters for accessing data in a struct</p><p><a href="https://go.dev/play/p/VEdBjISOboB">pattern 1</a></p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type Personal struct {<br>   Name string<br>}<br><br>func (p *Personal) GetName() string {<br>   if p == nil {<br>    return &quot;&quot;<br>   }<br>  <br>   return p.Name<br>}<br>type Data struct {<br>   Personal *Personal<br>}<br>func (d *Data) GetPersonal() *Personal {<br>   if d == nil {<br>    return nil<br>   }<br>  <br>   return d.Personal<br>}<br>func main() {<br>   var d *Data<br>   fmt.Printf(&quot;%q\n&quot;, d.GetPersonal().GetName())<br>}</pre><p><a href="https://go.dev/play/p/eY2yTbO2sZE">pattern 2</a></p><p>return meaningful value when a pointer receiver called on a nil</p><pre>package main<br>import &quot;fmt&quot;<br>type Node struct {<br>   next  *Node<br>   value int<br>}<br>func (n *Node) Next() *Node {<br>   if n == nil {<br>      return nil<br>   }<br>  <br>   return n.next<br>}<br>func (n *Node) Len() int {<br>   if n == nil {<br>      return 0<br>   }<br>  <br>   cnt := 0<br>  <br>   c := n<br>   for c != nil {<br>      c = c.Next()<br>      cnt++<br>   }<br>  <br>   return cnt<br>}<br>func main() {<br>   var n1 *Node<br>  <br>   fmt.Println(n1 == nil) // true<br>   fmt.Println(n1.Len())  // 0<br>}<br></pre><h3>Slice</h3><blockquote>nil slice has no backing array</blockquote><p>As we know slice has a descriptor with three elements</p><ol><li>pointer to the underlying array</li><li>length</li><li>capacity</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/0*-n0RUWfyikG0taqo.jpg" /></figure><p>What does a nil slice descriptor look likes?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*p3Ra1PebCdvyx4wj.png" /></figure><p>What can we do with a nil slice?</p><pre>arr == nil // true<br>len(arr) // 0<br>cap(arr) // 0<br><br>for range s // itertes zero time<br><br>s[10] // panic<br>// panic: runtime error: index out of range [10] with length 0<br><br>var s []string<br>for i := 0; i &lt; 10; i++ {<br> fmt.Printf(&quot;len: %d cap %d \n&quot;, len(s), cap(s))<br> s = append(s, &quot;str&quot;)<br>}<br>// len: 0 cap 0  // s is nil<br>// len: 1 cap 1  // allication<br>// len: 2 cap 2  // reallocation<br>// len: 3 cap 4  // reallocation<br>// len: 4 cap 4  <br>// len: 5 cap 8   // reallocation<br>// len: 6 cap 8 <br>// len: 7 cap 8 <br>// len: 8 cap 8 <br>// len: 9 cap 16   // reallocation</pre><p>Nil slice vs empty slice</p><pre>var arr []int // nil slice<br>arr == nil // true<br>len(arr) // 0<br>cap(arr) // <br><br>arr2 := []int{} // empty slice<br>arr2 == nil // false<br>len(arr2) // 0<br>cap(arr2) // 0</pre><p>We don’t have to treat them differently, but in some cases, it could be handy</p><p>for example, the Go JSON encoder encodes a Nil slice to null</p><pre>type Data struct {<br>   Arr []string<br>}<br>var nilSlice []string<br>emptySlice := []string{}<br><br>nilSliceResult, _ := json.Marshal(Data{Arr: nilSlice})<br>emptySliceResult, _ := json.Marshal(Data{Arr: emptySlice})<br><br>fmt.Println(string(nilSliceResult)) // {&quot;arr&quot;:null}<br>fmt.Println(string(emptySliceResult)) // {&quot;arr&quot;:[]}</pre><h3>Map</h3><blockquote>nil map are not initialized</blockquote><p>Map types are reference types, like pointers or slices, so the zero value of maps is <em>nil</em>.</p><p>It simply doesn’t point to an initialized map.</p><p>A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don’t do that.</p><pre>var m map[string]int<br><br>len(m) // 0<br>for k,v := range m // iterates zero times<br>v, ok := m[&quot;key&quot;] // 0(zero_value) false<br>m[&quot;key&quot;] = 10 // panic<br>// assigment to entry in nil map</pre><p>you can pass nil a read-only empty map:</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;log&quot;<br> &quot;net/http&quot;<br>)<br><br>func NewGetRequest(url string, headers map[string]string) (*http.Request, error) {<br> req, err := http.NewRequest(http.MethodGet, url, nil)<br> if err != nil {<br>  return nil, fmt.Errorf(&quot;new request failed: %v&quot;, err)<br> }<br><br> for k, v := range headers {<br>  req.Header.Set(k, v)<br> }<br><br> return req, nil<br>}<br><br>func main() {<br> if req, err := NewGetRequest(&quot;http://wwww.medium.com&quot;, nil); err != nil {<br>  log.Fatalln(err)<br> } else {<br>  response, _ := http.DefaultClient.Do(req)<br>  fmt.Println(&quot;response&quot;, response)<br> }<br>}</pre><h3>Function</h3><p>A function in Go is a first-class citizen that can be assigned to variables, passed as arguments, and returned as results. A nil function cannot be called until it is initialized.</p><p>You can pass nil as a function argument and use a default value if it’s nil.</p><pre>package main<br><br>import (<br> &quot;log&quot;<br>)<br><br>func DoSomething(logger func(v ...any)) {<br>   if logger == nil {<br>      logger = log.Println<br>   }<br>  <br>   logger(&quot;something&quot;)<br>}<br><br>func main() {<br>   DoSomething(nil)<br>}</pre><p>By passing a nil logger function to the DoSomething function in the main function, we can see how the function handles the case when a logger function is not provided.</p><h3>Channel</h3><blockquote>nil channel is a channel that is not initialized</blockquote><p>Looking at channel behavior in different states is a good idea to understand when and why we should use nil channel.</p><h4>Open Channel</h4><ol><li>sending and receiving from an open channel is allowed, and blocking.</li></ol><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;time&quot;<br>)<br><br>func main() {<br> c := make(chan int)<br><br> go func() {<br>  time.Sleep(10 * time.Second)<br>  c &lt;- 1997<br> }()<br><br> fmt.Println(&lt;-c) // block for 10 seconds<br>}</pre><h4>Closed Channel</h4><ol><li>If you close a closed channel, it will panic.</li><li>If you receive from a closed channel, it will return zero value of its type(not blocking)</li><li>If you send something to a closed channel, it will panic.</li></ol><pre>cc := make(chan string)<br>close(cc)<br>close(cc) // panic: close of closed channel<br>v,ok := &lt;-cc // zero value of string(&quot;&quot;) and false<br>v := &lt;-cc // zero value of string(&quot;&quot;)<br>cc &lt;- &quot;S&quot; // panic: send on closed chenne</pre><h4>Nil Channel</h4><pre>package main<br><br>import (<br> &quot;fmt&quot;<br>)<br><br>func main() {<br> var c chan int // nil channel<br><br> go func() {<br>  c &lt;- 1997 // blocking for ever<br> }()<br><br> fmt.Println(&lt;-c) // blocking for ever<br>}</pre><h4>To sum up</h4><pre>+---------------+---------+----------+<br>| channel state |  send   | receive  |<br>+---------------+---------+----------+<br>| open          | allowed | allowed  |<br>| close         | panic   | allowed  |<br>| nil           | blocked |  blocked |<br>+---------------+---------+----------+</pre><h4>When <strong>should</strong> we use a nil channel?</h4><p><a href="https://go.dev/play/p/w3l9tpvDp5z">example</a></p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;time&quot;<br>)<br><br>func Merge(c1 chan int, c2 chan int) chan int {<br> res := make(chan int)<br> go func() {<br>    for c1 != nil || c2 != nil {<br>     select {<br>         case v, ok := &lt;-c1:<br>            if !ok {<br>               c1 = nil<br>            } else {<br>               res &lt;- v<br>            }<br>         case v, ok := &lt;-c2:<br>            if !ok {<br>               c2 = nil<br>            } else {<br>               res &lt;- v<br>            }<br>         }<br>      }<br>      close(res)<br>   }()<br><br>   return res<br><br>}<br><br>func Generator(cnt, k int) chan int {<br>   c := make(chan int)<br>   go func() {<br>      for i := 0; i &lt; cnt; i++ {<br>         time.Sleep(time.Second)<br>         c &lt;- i * k<br>      }<br>      close(c)<br>   }()<br>   return c<br>}<br><br>func main() {<br>   c1 := Generator(3, 2)<br>   c2 := Generator(3, 3)<br>  <br>   c := Merge(c1, c2)<br>  <br>   for i := range c {<br>    fmt.Println(i)<br>   }<br><br>}</pre><p>The Merge function takes two integer channels, c1 and c2, and creates a new channel, res, that will contain the merged values of c1 and c2. The function then launches a goroutine that reads values from c1 and c2 until both channels have been closed. When a value is read from c1 or c2, it is sent to the res channel. If a channel is closed, its corresponding variable (c1 or c2) is set to nil to signal that there are no more values to be read from that channel. Once both c1 and c2 have been closed, the res channel is closed.</p><h3>Interface</h3><blockquote>nil interface have no value assigned, not even a nil pointer</blockquote><p>The interface descriptor has two values, a dynamic type, and a dynamic value.</p><p>for example (<a href="https://go.dev/play/p/DAhWApFboXT">playground</a>)</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type Notifier interface {<br>  Notify(string)<br>}<br><br>type User struct {<br>   Name string<br>}<br><br>func (u *User) Notify(msg string) {<br>  fmt.Printf(&quot;%s : %s&quot;, u.Name, msg)<br>}<br><br>func main() {<br>   var n1 Notifier<br>   n1 = &amp;User{&quot;Bill&quot;}<br>  <br>   n1.Notify(&quot;hi&quot;)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*At929rf9xEQowL_b.png" /></figure><p><strong>An interface equals nil if and only if both type and value are <em>nil</em>.</strong></p><p><a href="https://go.dev/play/p/aqK6Ks-tVrf">In the code below</a>, <em>u</em> is the pointer, and it is <em>nil</em> but <em>s</em> is an interface, and its type is <em>*User</em>, not <em>nil</em>, so it doesn’t equal <em>nil</em>.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type Notifier interface {<br>   Notify(string)<br>}<br><br>type User struct {<br>   Name string<br>}<br><br>func (u *User) Notify(msg string) {<br>   fmt.Printf(&quot;%s : %s&quot;, u.Name, msg)<br>}<br><br>func main() {<br>   var n Notifier<br>   var u *User<br>  <br>   n = u<br>  <br>   fmt.Println(u == nil) // true<br>   fmt.Println(n == nil) // false <br>}</pre><p>It could be more complicated; <a href="https://go.dev/play/p/S1UcrsO1zh_G">in the code below</a>,</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type doError struct{}<br><br>func (d *doError) Error() string { return &quot;&quot; }<br><br>func do() error {<br> var e *doError<br> fmt.Println(e == nil) // true<br> return e<br>}<br><br>func main() {<br> err := do()<br> fmt.Println(err == nil) // false<br>}</pre><ol><li>we check whether err equals nil.</li><li><em>err</em> is an error <em>interface,</em> and an <em>interface</em> is <em>nil</em> if its type and value both equal <em>nil</em>.</li><li>value of <em>err</em> is <em>nil,</em> but its type is <em>*doError</em></li></ol><p>Or even more complicated :D</p><pre><br>type doError struct{}<br><br>func (d *doError) Error() string { return &quot;&quot; }<br><br>func anotherDo() *doError {<br>   return nil<br>}<br><br>func WrapDo() error {<br>   return anotherDo()<br>}<br><br>func main() {<br> err := WrapDo()<br> fmt.Println(err == nil) // false<br>}</pre><h3>Conclusion</h3><p>In conclusion, nil is a powerful concept in Go that represents the absence of a value. By understanding when and how to use nil in different contexts, you can write more robust and efficient Go code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df33d1b0fd31" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>