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….
Blog
Remove or Strip all white spaces from a string in Go (Golang)
strings.ReplaceAll function can be used to trim all white spaces from a string in Golang. Below is the signature of the function s(first argument) is the input string old(second argument) is the…
Parse a bool or Check if given string is a bool in Go (Golang)
strconv.ParseBool() function can be used to parse a string representation of a bool. https://golang.org/pkg/strconv/#ParseBool Below is the signature of the function Let’s see a working code Output:
Parse a string to float in Go (Golang)
strconv.ParseFloat() function can be used to parse a string representation of a float https://golang.org/pkg/strconv/#ParseFloat Below is the signature of the function Some points worth noting The first argument is the string representation…
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…
Check if a environment variable is set in Go (Golang)
os.LookupEnv function can be used to check whether a particular environment variable is set or not. It returns a bool which is true if the given env variable set otherwise false. Let’s…
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:
Move file from one location to another in or command mv in Go (Golang)
os.Rename() function can be used to mv or move a file from one location to another. It is equivalent to command ‘mv’ of Linux. Below is the signature of the function Code:
List all env variables in Go
Overview os package provides an Environ() function to get the list all environment variables. Get all the env variables. It returns an array of string. There is also a way to clear…
Set or Unset or Get Environment Variables in Golang
Overview os package provides a couple of utility methods related to playing around env variables in Go. Setting an env value Get an env value The value returned by the Getenv() function…