What is the necessary knowledge to learn GO programming?
This article mainly introduces the necessary knowledge of learning GO programming, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. Environment variables:
Use go env to view environment variables
GOARCH/GOHOSTARCH: architecture, amd64 or 386
GOOS/GOHOSTOS: operating system, linux or windows
GOROOT: GO installation directory
GOBIN: GO program directory
GOTOOLDIR: GO tool catalog
CGO_ENABLED: whether to enable CGO
CC
CXX
GOGCCFLAGS
GORACE: data synchronization detection, with go test, go run, go build, go install-race option.
GOPATH: GO package lookup path
two。 Code organization:
-$GOPATH contains multiple workspace
-workspace contains src, pkg, bin
-src contains package, namely program, library
-package contains go file
Need to understand:
* package name vs package path
Package name refers to the identifie. Package name declared with package in go file. Package path refers to the path relative to GOPATH. Same package path, same package name.
Package import complete syntax:
Import [name] "path"
Where:
The name part can
None, using the default name declared by package
Point, using the current package
Blank, execute init only
Name, custom name
The path part can
Absolute path: the path relative to $GOPATH
Relative path: the path relative to the current file.
Note: there can be no relative paths using the vendor mechanism, otherwise the parsing error will occur.
* program vs library
Package name represents program for main
Package name is not main for library
3. Code testing
Execute the test code using the go test command.
Test file is suffixed with _ test.
Test func is prefixed with Test.
4. Remote packet
Use the go get command to get the remote package.
However, the go test command relies on git or svn.
Thank you for reading this article carefully. I hope the article "what is necessary to learn GO programming" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!