Golang
| Introduction | |
| Comments | |
| Code formatting | |
| Installation | |
| Team go. | |
| Setting up Visual Studio Code | |
| Run the script | |
| module | |
| Other articles on Go |
Introduction
Go (often also golang) is a compiled multithreaded programming language developed internally by Google.
Development of Go began in September 2007 and was directly designed by Robert Griezmer, Rob Pike, and Ken Thompson, who had previously worked on the Inferno operating system.
The language was officially introduced in November 2009. At the moment, the official compiler developed by the creators of the language is supported for FreeBSD operating systems.
OpenBSD
,
Linux
, macOS,
Windows
, DragonFly BSD, Plan 9, Solaris, Android, AIX..
Go is also supported by a set of gcc compilers, there are several independent implementations. A second version of the language is being developed.
Online IDE
play.golang.org
Comments
Created with // or /* */ - as in PHP
package main
// Comments
/*
Comment
Across several
lines
*/
Code formatting
Retreats should be put with the help of tabulation. Not with spaces.
A gap or no tab will not break the compilation but is recommended by the community
package main
import (
"fmt"
)
The function announcement and the opening bracket should be on the same line
func main() {
fmt.Println("Visit heihei.ru")
}
If you put { on the next line, go automatically put a semicolon after () and the compilation breaks.
./prog.go:7:6: missing function body
./prog.go:8:1: syntax error: unexpected semicolon or newline before {
If you make such a mistake in the sandbox, you can click on Format. And he'll give you a clue.
prog.go:8:1: unexpected semicolon or newline before {
Installation
About installation in
Linux
read the article
«How to install Golang on Linux»
To set in
Windows
Just download Go with
golang.org
and set it to C:\Go\
This is important because Go implies that it is installed in
C:\Go\ in Windows and in ~/go in Linux
Team go.
Execute command go without argument
go
Go is a tool for managing Go source code.
Usage:
go
An example of using go help doc can be found. here
go help doc
Setting up Visual Studio Code
Install.
Visual Studio Code
Then you need to install the extension Go.
Rich Go language support for Visual Studio Code
Then press.
Ctrl + Shift + P
Search for it.
Go: Install/Update Tools
Select everything and press OK.
All tools successfully installed. You're ready to Go :).
Script launch
Let's look at the script. main.go with the following content
package main
import "fmt"
func main() {
fmt.Println("Visit TopBicycle.ru")
}
go run main.go
Visit TopBicycle.ru
module
Projects should be designed in the form of modules.
mkdir ~/gocode
cd ~/gocode
go mod init github.com/youraccount/projectname
go: creating new go.mod: module github.com/youraccount/projectname
It is advisable to immediately name them so that there is a correspondence between the project and the remote repository.
About git, github, gitlab and similar topics can be read in the article
git
After initialization, a file will appear. go.mode with the following content
module github.com/youraccount/projectname
go 1.16
Create a file.
main.go
as in the previous paragraph.
It can now be launched as a module.
go run github.com/youraccount/projectname
Article author: Andrei Olegovich
| Development in Go | |
| Variable declaration | |
| Determine the variable type | |
| Pointers | |
| Constants | |
| Installation in Linux | |
| Go course: zero to hero in 50 lessons |