<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Basics on Go Basics Training</title><link>/docs/basics/</link><description>Recent content in Basics on Go Basics Training</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/basics/index.xml" rel="self" type="application/rss+xml"/><item><title>Variables</title><link>/docs/basics/variables/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/variables/</guid><description>Basics Go is a statically typed language. This means that each variable gets a type on declaration which can&amp;rsquo;t be changed later.
Commonly used data types are:
int and uint float32 and float64 bool string byte (alias for uint8) error to return errors from functions All Go&amp;rsquo;s predeclared identifiers are defined in the builtin package.
Declaration The short assignment statement := declares a variable and assigns a value to it. The type of variable is inferred from the value (type inference).</description></item><item><title>Flow control</title><link>/docs/basics/flow-control/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/flow-control/</guid><description>If Else Conditionals in Go are similiar to other programming languages. Notice that there are no round brackets surrounding the condition.
1 2 3 4 5 6 7 8 9 10 11 12 package main import &amp;#34;fmt&amp;#34; func main() { x := 10 if x &amp;gt;= 5 { fmt.Println(&amp;#34;X is greater or equal to 5&amp;#34;) } else { fmt.Println(&amp;#34;X is smaller than 5&amp;#34;) } } Output: X is greater or equal to 5 Multiple logical conditions can be combined with &amp;amp;&amp;amp; (AND) and || (OR).</description></item><item><title>Functions</title><link>/docs/basics/functions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/functions/</guid><description>Basics The func keyword declares a function.
In the following example we declare the function add. It takes two parameters a and b of type int and returns a value of type int which is the sum of a and b.
1 2 3 4 5 6 7 8 9 10 11 12 package main import &amp;#34;fmt&amp;#34; func add(a int, b int) int { return a + b } func main() { result := add(2, 3) fmt.</description></item><item><title>Pointers</title><link>/docs/basics/pointers/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/pointers/</guid><description>Basics In addition to the basic data types Go also have pointers. A pointer contains a memory address of an actual value or nil if they do not point to anything. The zero value of a pointer is nil.
Pointer types are indicated with a star. For example:
The type *int is a pointer to an int The type *bool is a pointer to a bool Concerning pointers you mainly have to remember two operations.</description></item><item><title>Structs</title><link>/docs/basics/structs/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/structs/</guid><description>Basics Structs are used to group related variables called fields. In that respect structs in Go are similar to classes or objects in other languages.
Declare Struct Type This statement declares a new struct type called User. This struct contains three fields. The name of the user (string), the number of failed login attempts (int) and if the user is locked (bool):
type User struct { Name string FailedLogins int Locked bool } Create Instance A new struct instance can be created using a struct literal:</description></item><item><title>Slices</title><link>/docs/basics/slices/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/slices/</guid><description>Basics With a slice literal (e.g. []int{1, 2, 3}) and the short assignment we we can initialize a new slice. Slices store multiple items of the same type.
1 2 3 4 5 6 7 8 9 package main import &amp;#34;fmt&amp;#34; func main() { q := []int{2, 3, 5, 7, 11, 13} fmt.Println(q) fmt.Println(&amp;#34;Length of slice:&amp;#34;, len(q)) } Output: [2 3 5 7 11 13] Length of slice: 6 Slice of structs We can also store multiple instances of a struct.</description></item><item><title>Maps</title><link>/docs/basics/maps/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/maps/</guid><description>Basics A map maps keys to values. In other languages it is also called hash map or dictionary. The following example shows how to:
initialize a map with an empty map literal set a value by key get a value by key delete a key get the length of the map 1 2 3 4 5 6 7 8 9 10 11 12 13 package main import &amp;#34;fmt&amp;#34; func main() { m := map[string]int{} m[&amp;#34;john&amp;#34;] = 66 fmt.</description></item><item><title>Interfaces</title><link>/docs/basics/interfaces/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/basics/interfaces/</guid><description>Basics Interfaces are used to express general behaviour across multiple types. Interface types are defined as a set of method signatures. All types which implement this set of methods implement the defined interface.
As an example we define the interface Stringer:
type Stringer interface { String() string } All types that implement the method String() and return a string implement the Stringer interface. Types implicitly implement an interface if they implement the required methods.</description></item></channel></rss>