Start learning Go
I’m going to spend 14 days learning the basics of Go. Here’s the work for day one.
Practice
-
Install the latest Go (1.26.1) from the official website Go Programming Language
-
Install the latest Visual Studio Code (1.114.0) from the official website Visual Studio Code - The open source AI code editor
-
Update PowerShell to version 7.6.0 from github PowerShell/PowerShell: PowerShell for every system!
-
Open Visual Studio Code, Click Extensions on the left sidebar, search for ‘Go’ in the search bar at the top
-
Install the first extension provided by Go Team at Google
-
Open terminal in Visual Studio Code using PowerShell and type:
go versionIt will return something like:
go version go1.26.1 windows/amd64 -
Create a file named
hello.goand write the first Go program:package main import "fmt" func main() { fmt.Println("Go installed successfully!") } -
Press Ctrl + S to save the file.
-
In terminal run command:
go run hello.goIt will output:
Go installed successfully -
The first Go program is complete.
Key Concepts
-
There’s no semicolon in the code, Go doesn’t require semicolons to end statements, the Go compiler automatically inserts them during parsing.
-
package main
- The keyword
packageis similar to Java’spackage, but in Go it defines a module namespace. - Only the
mainpackage is executable, other packages are used as libraries. - In this code, we need to run the code directly, so it has to belong to
package main
- The keyword
-
import “fmt”
- The keyword
importcan only be used to import package, since Go has no classes.
- The keyword
-
func main()
- Go uses the keyword
functo declare functions. The full syntax is:
func [receiver] FunctionName[TypeParams](parameters)(returnTypes) { // body }- If the function name starts with an uppercase letter, it is public, if it starts with a lowercase letter, it is private.
- Go uses the keyword
-
fmt.Println()
- Call the Println() function from the fmt package