Getting started with Go

Posted May 25, 20202 min read

Go

GO language

The Go language that has been heard for a long time, let's get started today.

One of the reasons why Go is popular is that it has CoreOS, Kubernetes(Google), InfluxDB well-known large customers, and Docker is also written in Go language.

Functional features of Go language(all these features, learn slowly and understand later)

  • Concurrency support
  • Simplicity and consistency
  • Object-oriented
  • Pointer
  • translater
  • Package management

Go language standard library address

https://golang.org/pkg official website

https://studygolang.com/pkgdoc Chinese

Project source address

https://github.com/golang/go

Get started quickly

Through the installation package

Domestic download address: https://studygolang.com/dl

Configuration

  ~ go version
go version go1.14.3 darwin/amd64
# If the command does not exist, add environment variables
# ~/.bash_profile
export PATH = $PATH:/usr/local/go/bin

Accelerator is necessary in China

# Enable Go Modules function
go env -w GO111MODULE = on
go env -w GOPROXY = https://goproxy.io
go env -w GOPROXY = https://goproxy.cn
go env -w GOPROXY = https://mirrors.aliyun.com/goproxy/

# Go version> = 1.13
go env -w GOPROXY = https://goproxy.io,direct
# Set the private warehouse without proxy, multiple separated by commas
go env -w GOPRIVATE = *. example.com

# Detection
go env | grep GOPROXY
go env | grep GOBIN

Open Go's "Hello world"

Create file hello.go file

package main

import "fmt"

func main() {
    fmt.Printf("hello, world \ n")
}

run

$go run hello.go
hello, world

Compile

 go build -o hello hello.go
 # executable file
 ./hello
 Hello, world.

Mac | exe files can also be compiled on Linux

GOOS = windows go build -o hello.exe hello.go

Windows compilation

go build -o hello.exe hello.go

See the address below for more

https://github.com/golang/go/...

IDE

The choice of tools seems to be more vscode, the other is GoLand, attach the address

https://code.visualstudio.com

https://www.jetbrains.com/go

Use vscode, add go plugin

Plugin

Collect some learning materials

Go official website blog https://blog.golang.org

Go Chinese Community https://studygolang.com

Knowledge Graph https://github.com/gocn/knowl...

Chinese Online https://mikespook.com/learnin...