os.Remove() function can be used to delete a file in Golang. Below is the signature of this function Code: Output:
Tag: golang
Write multiline string in Go (Golang)
A backquote (`) can be used to write a multiline string in Golang. Note that a string encoded in backquotes is a raw literal string and doesn’t honor any kind of escaping….
Check if a string is a number in Go (Golang)
strconv.Atoi() function can be used to check if the string is a number. If this function returns an error if the passed string is not a number. This function parses the number…
Get number of currently running/active goroutines
NumGoroutine function of runtime package can be used to know the currently running/active goroutines. https://golang.org/pkg/runtime/#NumGoroutine Below is the signature of the function Working Code: Output:
Download an image or file from a URL in Go (Golang)
Overview Below are the steps to download an image or a file from a URL use http.Get(URL) function to get the bytes of the file from the URL. Create an empty file…
Create a new time instance in Go (Golang)
In Go time.Time struct is used to represent an instance of time or date. Below are three ways of creating a new time instance Using time.Now() time.Now() function can be used to…
Time/Date Formatting in Go
If you have worked with time/date formatting in other languages you might have noticed that the other languages use special placeholders for time/date formatting. For eg ruby language uses %d for day…
Get age given a DOB in Go (Golang)
This tutorial will talk about how given a date of birth we can compute the age of a person. go-age comes to our rescue for doing that. It also takes into account…
Get Current Working Directory in Go (Golang)
os.Getwd() is used to get the current working directory. Output will similar to pwd command on linux Output: Current Working Direcoty: <will be current working directory on the machine>
Iterative Binary Search Tree in Go (Golang)
Introduction A binary search tree abbreviated as BST is a binary tree. For each node in a Binary Search Tree Value of each node in the left subtree is less than the…