当前位置:网站首页>Environment construction of go language foundation

Environment construction of go language foundation

2022-06-23 22:06:00 Ink purple feather ink

One 、go Download and install of

1、 Download address :https://golang.google.cn/dl/

2、 install : When the download is complete ,Windows Double click the version to install ( Remember this installation address , You need to use... When configuring environment variables later )

3、 Check :win+R Input cmd Enter to open the terminal window , Input go If the following information is available, the installation is successful

4、 establish go Working space for (GOPATH The directory that the environment variable points to )

GO The code must be in the workspace . The workspace is a directory , It contains three subdirectories :

  • src ---- Every subdirectory in it , It's just a bag . Inside the bag is Go Source file
  • pkg ---- Generated after compilation , The target file for the package
  • bin ---- Generated executable file

Two 、GOPATH Set up

  • GOROOTGo The path to the root directory of the language installation , That is to say GO Language installation path .
  • GOPATH: Is an environment variable , Used to show what you wrote go The storage path of the project . It is better to set only one path , All project code is put in GOPATH Of src Under the table of contents
  • GOBINGO Executable files generated by the program (executable file) The path of .

We can GOPATH It is simply understood as Go Working directory of languages , Its value is the path to a directory , It can also be multiple directory paths , Each directory represents Go A workspace for languages (workspace). We need to benefit these workspaces , To place Go Language source file (source file), And installation (install) Archive after (archive file, That is to say “.a” File with extension ) And executables (executable file). in fact , because Go All operations of a language project in its life cycle ( code 、 Dependency management 、 structure 、 test 、 Installation, etc ) Basically around GOPATH And work area .

1、 Environment variable configuration :

  1. My computer -> attribute -> Advanced system setup -> environment variable
  2. newly added GOPATH Set the value as you want to save go Code directory

3、 To configure path: hold go Installation directory and gopath Directory configuration

4、 Check : stay cmd Enter... In the terminal box go env If any, as shown in the figure gopath It means that the setting is successful

3、 ... and 、vscode Download and install of

1、 Download address :https://code.visualstudio.com/

2、 install : When the download is complete , Double click Install directly , And then the next step 、 The next step is to

3、 To configure :

  • Configure Chinese
  • install go plug-in unit

Four 、hello world Program

1、 Use vscode Open our new project directory , Write our first go Language program

2、 stay src Create a new one under the directory hello The catalog of , Then I'm building a new hello.go file

package main
import "fmt"

func main(){
	fmt.Println("hello world")
}

3、 Click View in the menu bar -> terminal , Input go run hello/hello.go

原网站

版权声明
本文为[Ink purple feather ink]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112200837452619.html