Go is one of the modern programming languages gaining traction on many surveys as developers preferred language.
Go has an easy-to-use and understand syntax while providing top-tier performance.
Gos ecosystem of third-party packages supports many other use cases.
Getting Started With Go
you’re free to run Go on most operating systems.
Head tothe installations pageand download a preferred Go version for your operating system.
Once youve downloaded and installed Go, you canstart writing and running Go codein files with a.gofile extension.
Youll find Go has most of the features and much of the functionality of other programming languages.
If you have previous programming experience, you should find Go straightforward.
Variables in Go
Go is quite expressive on the fundamental level.
There are two ways it’s possible for you to declare variables in Go.
you could use thevarkeyword to declare variables of various data types.
After specifying the identifier, youll have to set the variable’s data key in.
you’re free to also declare constants with theconstkeyword in a similar fashion to declaring variables.
It is impossible to modify constants after their declaration.
Go provides an alternative way to declare variables in functions.
you’ve got the option to use theifandelsestatements in your code to handle decisions.
Go doesnt provide else-if statements, but you’re able to useswitchstatements for complex conditional statements.
Heres the anatomy of aswitchstatement in Go.
you could handle the default case using adefaultkeyword.
you’re able to use the popular C-style for-loop or therangefor-loop that certain data structures support.
Therangefunction returns the index and element of the index as it traverses the data structure.
Arrays in Go
Arrays are one of the compound data types in Go.
Go arrays are similar to C-style arrays and have a definite length on declaration and instantiation.
Slices are similar to arrays, except that you’re free to change the length of slices.
Youll need to use the built-inmakefunction to create a slice.
Pass in the slices data bang out and initial length to the make function.
it’s possible for you to use the append function to insert elements into slices.
By default, theappendfunction inserts elements at the end of the slice.
Maps in Go
Maps are the built-in associative (key-value pair) data bang out in Go.
you’re able to access values in a map by specifying the keys.
Also, you’re free to insert values into a map by specifying a key-value pair.
it’s possible for you to use thedeletefunction to remove key-value pairs from maps.
Youll have to specify the argument bang out alongside the identifier for arguments.
Structs in Go
Go isnt anobject-oriented languageby design, butyou can implement object-oriented features in Gousing structs.
Structs are user-defined types for grouping other data types into a single entity.
Go structs can hold values of any Go-supported types, and functions can implement structs.
it’s possible for you to instantiate structs with default values or assign values to them.
Functions can implement and access struct types.
Youll have to specify the struct parameter before the functions identifier.
There are many fields and applications where you might use Go.