1. Installation
Equipment environment: win10 home version
1. Download:
Installation and download address: https://studygolang.com/dl
Click to download directly, and click "next" in a foolish way.
2. Configuration:
After the successful installation of go, you need to configure the environment variables.
This computer-Properties-Advanced System Settings-Advanced (select environment variables)
-System environment variables to create GOPATH
in the GOPATH point to the location to create a new folder
description:
bin (store the generated after compilation Execution file)
pkg (store the package file generated after compilation)
src (store the project source code)
PS : The location of the file downloaded by Go and GOPATH should not be the same location, and GOPATH is the project address.
3. Inspection
CMD input go env will display the current configuration information of the go language
二、Hello World
Writing environment description: Currently, due to the new installation, no IDE and compiler are used. Temporary text file preparation.
Create a hello.go file under src,
open it, write the code, and save
package main
import (
"fmt"
)
func main(){
fmt.Println("Hello world!你好!")
}
Enter the file location on the console and execute the command go run hello.go
Common Go commands
go get: get the remote package (you need to install git or hg in advance)
go run: run the program directly
go build: test the compilation, check for compilation errors
go fmt: format the source code (some IDEs are automatically called when saving)
go install: compile Package file and compile the entire program
go test: run the test file
go doc: view the document