Golang

Contents
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 [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get add dependencies to current module and install them install compile and install packages and dependencies list list packages or modules mod module maintenance run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help " for more information about a command. Additional help topics: buildconstraint build constraints buildmode build modes c calling between Go and C cache build and test caching environment environment variables filetype file types go.mod the go.mod file gopath GOPATH environment variable gopath-get legacy GOPATH go get goproxy module proxy protocol importpath import path syntax modules modules, module versions, and more module-get module-aware go get module-auth module authentication using go.sum packages package lists and patterns private configuration for downloading non-public code testflag testing flags testfunc testing functions vcs controlling version control with GOVCS Use "go help <topic>" for more information about that topic.

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

Related articles
Development in Go
Variable declaration
Determine the variable type
Pointers
Constants
Installation in Linux
Go course: zero to hero in 50 lessons

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: