If i want to start learning Go syntax, please familiarize yourself with the following 4 points:

Environment variable:

View environment variables with go env

goarch/gohostarch:architecture, amd64 or 386

goos/gohostos:operating system, linux or windows

goroot:go installation directory

gobin:go program directory

gotooldir:go tool directory

cgo_enabled:whether to enable cgo




gorace:data synchronization detection, With the -race option of go test, go run, go build, go install.

gopath:Go package search path

2. Code organization:

-$gopath contains multiple workspaces

-workspace contains src, pkg, bin

-src contains package, namely program, library

-package contains go file

Need to understand:

* package name vs package path

The package name refers to the identifie declared by the package in the go file. The package path refers to the path relative to the gopath. The same package path, the same package name.

package import complete syntax:

import [name] "path"

among them:

name part can

None, use the default name declared by the package

Point, use current package

blank, execute only init

name, custom name

path part can

Absolute path:path relative to $gopath

Relative path:The path relative to the current file.

Note:relative paths cannot occur using the vendor mechanism, Otherwise parsing error.

* program vs library

package name is main means program

package name non-main means library

3. Code testing

Use go test command to execute test code.

The test file is suffixed with _test.

test func is prefixed with test.

Remote package

Use the go get command to get the remote package.

But the go test command relies on git or svn.

  • Previous Method to prevent mysql from repeatedly inserting records
  • Next Fifty-nine of manipulating data in ASPNET 20: using SQL cache dependency SqlCacheDependency