Overview Function closures are nothing but an anonymous function that can access variables declared outside the function and also retain the current value of those variables between different function calls. Anonymous functions…
Author: admin
IIF or Immediately Invoked Function in Go (Golang)
Overview: IIF or Immediately Invoked Function are those function which can be defined and executed at the same time. A function can be invoked immediately by appending a () after the end…
Check if an item exists in a slice in Go (Golang)
Let’s see a working code Output:
Get the IP address from an incoming HTTP request
Overview In this article, we will get the IP address of the client for an incoming HTTP request using X-REAL-IP header If X-REAL-IP is empty then we will fall back to X-FORWARDED-FOR header….
Understanding WaitGroup in Go (Golang)
WaitGroup is a struct that is part of sync package in Go. It is generally used to wait for a collection of goroutines to finish execution. The WaitGroup has below methods Add…
Wait for all Go routines to finish execution in Golang
sync package of golang provides WaitGroup struct which can be used to wait for collection of goroutines to finish execution. The WaitGroup provides: Add method to set the number of goroutines to…
Detect OS in Go (Golang)
runtime.GOOS constant can be used to detect the OS at runtime since this constant gets set only at runtime. runtime.GOARCH can be used to know the architecture target of the running program….
Change the modified/updated time and access time of a file in Go (Golang)
os.Chtimes() function can be used to change the mtime(modified time) or atime(access time) of a file in Golang. Below is the signature of the function. Code: Output:
Delete/Remove a folder in Go (Golang)
os.Remove() function can be used to delete a folder in Golang. Below is the signature of this function Code: Output:
Delete a file in Go (Golang)
os.Remove() function can be used to delete a file in Golang. Below is the signature of this function Code: Output: