HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
To start using Go, you need two things
To start using Go, you need two things:
There are many text editors and compilers to choose from. In this tutorial, we will use an IDE (see below).
You can find the relevant installation files at https://go.dev/dl/.
Follow the instructions related to your operating system. To check if Go was installed successfully, you can run the following command in a terminal window:
go version
Which should show the version of your Go installation.
An IDE (Integrated Development Environment) is used to edit AND compile the code.
Popular IDE's include Visual Studio Code (VS Code), Vim, Eclipse, and Notepad. These are all free, and they can be used to both edit and debug Go code.
We will use VS Code in our tutorial, which we believe is a good place to start.
You can find the latest version of VS Code at visualstudio.
Let's create our first Go program.
Ctrl + Shift + x
Ctrl + Shift + p
Go: Install/Update Tools
commandVS Code is now configured to use Go.
Open up a terminal window and type:
go mod init example.com/hello
Do not worry if you do not understand why we type the above command. Just think of it as something that you always do, and that you will learn more about in a later chapter.
Create a new file (File > New File
). Copy and paste the following code and save the file as helloworld.go
(File
> Save As
):
package main
import ("fmt")
func main() {
fmt.Println("Hello World!")
}
Now, run the code: Open a terminal in VS Code and type:
go run .\helloworld.go
Hello World!
If you want to save the program as an executable, type and run:
go build .\helloworld.go
When learning Go at W3C, you can use our "Try it Yourself" tool. It shows both the code and the result. This will make it easier for you to understand every part as we move forward:
Code:
package main
import ("fmt")
func main() {
fmt.Println("Hello World!")
}
Result:
Hello World!