GoLang

GO Workspace
In Go, programs are kept in a directory hierarchy that is called a workspace. A workspace is simply a root directory of your Go applications. A workspace contains three subdirectories at its root:

src – This directory contains source files organized as packages. You will write your Go applications inside this directory. pkg – This directory contains Go package objects. bin – This directory contains executable programs.

Packages
In Go, source files are organized into system directories called packages, which enable code reusability across the Go applications. The naming convention for Go package is to use the name of the system directory where we are putting our Go source files. Within a single folder, the package name will be same for the all source files which belong to that directory. We develop our Go programs in the $GOPATH directory, where we organize source code files into directories as packages. In Go packages, all identifiers will be exported to other packages if the first letter of the identifier name starts with an uppercase letter. The functions and types will not be exported to other packages if we start with a lowercase letter for the identifier name.

Go’s standard library comes with lot of useful packages which can be used for building real-world applications. For example, the standard library provides a “net/http” package which can be used for building web applications and web services. The packages from the standard library are available at the “pkg” subdirectory of the GOROOT directory. When you install Go, an environment variable GOROOT will be automatically added to your system for specifying the Go installer directory. The Go developer community is very enthusiastic for developing third-party Go packages. When you develop Go applications, you can leverage these third-party Go packages

A console traditionally refers to a computer terminal where a user may input commands and view output such as the results of inputted commands or status messages from the computer. The console is often connected to a remote computer or computer system that is controlled from the console. Consoles are completely text-based, which means you can operate them without touching your keyboard, which reduces the time it takes to complete tasks, because you don’t have to reach over to the mouse as often.

Binary files contain a series of characters. For binary files, the system does not translate control characters on input or output. Under z/OS XL C/C++, some types of files are always treated as binary files, even when opened in text mode. In such cases, a control character is written to the file as binary data. On input, the control character will be read back as it was written. See the topic about the byte stream model in z/OS XL C/C++ Programming Guide for more information.

Package Main
When you build reusable pieces of code, you will develop a package as a shared library. But when you develop executable programs, you will use the package “main” for making the package as an executable program. The package “main” tells the Go compiler that the package should compile as an executable program instead of a shared library. The main function in the package “main” will be the entry point of our executable program. When you build shared libraries, you will not have any main package and main function in the package.

Main function
A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name main and declare a function main that takes no arguments and returns no value. Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete. The language specification does not give special meaning to the name main outside of this context. The name main is not a reserved name. It's OK to declare a main function in non-main packages. In such cases, it's just a function named main.

Init Function
When you write Go packages, you can provide a function “init” that will be called at the beginning of the execution time. The init method can be used for adding initialization logic into the package.

In Go, := is for declaration + assignment, whereas = is for assignment only. For example, var foo int = 10 is the same as foo := 10.

Operators
An operator is a symbol that tells the compiler to perform certain actions. The following lists describe the different operators used in Golang.


 * 1) Arithmetic Operators
 * 2) Assignment Operators
 * 3) Comparison Operators
 * 4) Logical Operators
 * 5) Bitwise Operators

1. Arithmetic Operators in Go Programming Language The arithmetic operators are used to perform common arithmetical operations, such as addition, subtraction, multiplication etc. Here's a complete list of Golang's arithmetic operators:

2. Assignment Operators in Go Programming Language. The assignment operators are used to assign values to variables

Comparison Operators in Go Programming Language Comparison operators are used to compare two values.

Operator			Name				Example	Result

Equal				x
y	True if x is equal to y !=				Not equal			x != y	True if x is not equal to y <				Less than			x < y	True if x is less than y <=				Less than or equal to		x <= y	True if x is less than or equal to y >				Greater than			x > y	True if x is greater than y >=				Greater than or equal to	x >= y	True if x is greater than or equal to y

Logical Operators in Go Programming Language Logical operators are used to determine the logic between variables or values.

Operator		Name			Description						Example &&			Logical And		Returns true if both statements are true		x < y && x > z !			Logical Not	Reverse the result, returns false if the result is true		!(x == y && x > z)
 * Logical Or		Returns true if one of the statements is true		x < y || x > z

Bitwise Operators in Go Programming Language Bitwise operators are used to compare (binary) numbers.

Operator			Name			Description &				AND			Sets each bit to 1 if both bits are 1 ^				XOR			Sets each bit to 1 if only one of two bits is 1 <<				Zero fill left shift	Shift left by pushing zeros in from the right and let the leftmost bits fall off >>				Signed right shift	Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
 * OR			Sets each bit to 1 if one of two bits is 1