Defer, Panic, and Recover in Go.
panic
During a typical panic, normal execution stops, all deferred function calls in that goroutine are executed, and the program crashes with a log message.
package main
func main() {
panic("invalid")
}
...
Understanding defer in Go.
Deferred Function Calls
A defer statement is an ordinary function or method call prefixed by the keyword defer. The function and argument expressions are evaluated when the statement is executed, but the actual call is def...
In Golang, using the exec.Command() function is the easiest way to execute a shell command
Using exec.Command Function
Command returns the Cmd struct to execute the named program with the given arguments.
You can execute a shell command using the e...
In Python, there are 3 ways to execute a program or call a system command.
Using subprocess Module
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. See the following e...
In Python, there are 3 ways to check if a file exists.
Using os.path.exists Method
Return True if path refers to an existing path or an open file descriptor. Returns False for broken symbolic links. On some platforms, this function may return False ...
List of Golang Keywords.
Keywords
The following keywords are reserved and may not be used as identifiers.
break default func interface select
case defer go map struct
chan else goto package switch
const ...
3 ways to find a key in a map.Use second return value directly in an if statement
If "BST" is indeed present in the map, the body of the if statement will be executed and v will be local to that scope.
package main
import "fmt"
func main() {
di...
history command is used to view the previously executed command.
The history command works with the command history list. When the command is issued with no options, it prints the history list.
The History library provides a history expansion featur...
Display amount of free and used memory in the system.
free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo....
command line tool and library for transferring data with URLs.
cURL (pronounced 'curl') is a computer software project providing a library (libcurl) and command-line tool (curl) for transferring data using various network protocols. The name ...
chmod is the command and system call used to change the access permissions of file system objects (files and directories) sometimes known as modes.
The chmod command sets the file permissions flags on a file or folder. The flags define who can read,...
Alias command instructs the shell to replace one string with another string while executing the commands.
The alias command lets you give your own name to a command or sequence of commands. You can then type your short name, and the shell will execu...
Go mod provides access to operations on modules.
Initialize new module in current directory. If you plan to publish your module for others to use, the module path must be a location from which Go tools can download your module.
go mod init ...
Remove object files and cached files.
Clean removes object files from package source directories. The go command builds most objects in a temporary directory, so go clean is mainly concerned with object files left by other tools or by manual invocati...
Go is a tool for managing Go source code.
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Go install.
1. Extract the archive you downloaded into /usr/local, creating a Go tree ...