<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>defer on Golang</title><link>https://golang.k5kc.com/tags/defer/</link><description>Recent content in defer on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:10:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/defer/index.xml" rel="self" type="application/rss+xml"/><item><title>Go - defer</title><link>https://golang.k5kc.com/2020/08/16/11.defer/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/11.defer/</guid><description>The defer statement is used to postpone a function call executed immediately before the surrounding function returns. The common uses of defer include releasing resources (i.e., unlock the mutex, close file handle.), do some tracing(i.e., record the running time of function), etc. E.g., an ordinary accessing global variable exclusively is like this:
var mu sync.Mutex var m = make(map[string]int) func lookup(key string) int { mu.Lock() v := m[key] mu.Unlock() return v } An equivalent but concise format using defer is as follow:</description></item><item><title>Go - literals</title><link>https://golang.k5kc.com/2020/08/16/10.literals/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/10.literals/</guid><description>literal means the value itself. Unlike variable, a literal doesn&amp;rsquo;t have a name.</description></item></channel></rss>