- Basic constructs and primitive data types
- Control structures
- Arrays and Slices
- Functions and Methods
- Goroutines and Channels
- Error handling
Almost all of the DevOps tools developed in Go.
For a complex task python is slow to process.
Total 25 keywords in Golang and it’s the base of all those complex codes written in the industry.
Go will force a developer to write code in a complex way.
No compilation complexities with exceptional backward complexity.
Introduced by Google
Designed by Robert Griesmer, Rob Pike and Ken Thompson
Open Source version released in 2009
Go language is easy to use in advanced programming compared to Golang.
Slowness in python as it works using external packages and package dependencies
• Statically typed
• Its compiled language
• Cross compilation . We don’t need a specific OS platform to develop a binary
• Garbage collection. Memory management
• Built-in concurrency
• Compile to standalone libraries
Variable will define using a keyword var.
Starts with letter or _
_ or blank identifier
Basic data types:
Primitive data types and derived data types
Numeric : intiger, floating point, complex
Boolian : default false
Text : string
Composite : array,structs etc
Constants will not change during a program execution
Typed constants and untyped constants
All go files need to be defined in a package
We can import additional package specifing package path URL
Its a way to structure the code
Conditional and branching structures and iterative looping structure.
Similar to other programming languages like go have if, if else, for, etc..
In go switch case does not have any break statement
While and do while is not there in go.
While loop can handle using for itself in go.
Specify length while initialize and array
default value will be Nill
Slice is a reference to a portion of an array
Slice in memory is a structure with 3 fields
A pointer to underlying array
Length of slice
Capacity of the slice
Unordered collection of pairs of items
Key value pairs
Its a variable that stores memory address of other variable
Default value is nil
Does not support pointer arithmetic
Nil pointer dereference is not allowed
Heterogeneous data type
Collection of fields
Struct field accessed using a dot
Struct fields can be accessed through a struct pointer
Embedded struct – can assign other struct inside a struct
Functions and Methods
Function can take zero or more arguments
Method is a function act on a variable of a certain type called receiver
Value receivers and pointer receivers
Its a functional language
A way to specify behaviour of an object
Building blocks of structuring concurrent programs are goroutines and channels
Goroutine is a lightweight thread managed by go runtime
Possible to run multiple threads in go routine
Used to communicate between goroutines
Does not have an exception handling
Can’t throw exceptions
Is there any relation between Go and Go template
Ans : Go templating is framework