If i want to start learning Go syntax, please familiarize yourself with the following 4 points:
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"
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.
Use the go get command to get the remote package.
But the go test command relies on git or svn.
- Golang minimalist tutorial (1): basic concepts
- Understanding arrays, slices and maps in Golang
- Mac OS system installation golang tutorial
- C code examples in Golang
- For loop statement usage example in golang language
- Golang minimalist tutorial (4): writing the first project
- Go language environment under ubuntu
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- dart - flutter: the instance member'stars' can't be accessed in an initializer error