The main contents of this paper are as follows:

  1. Download and install GO
  2. Configure multiple workspaces, the first for third-party packages by default, and the others for project code
  3. A package managergodepInstallation and use of
  4. Some pits (walls) during installation
  5. Vscode uses go

1. Download and install itgo

Golang is installed on C:\GO by default. Use GO version to view the version:



1.10

2. Create a workspace

  1. Create two new folders: DepSource\ SRC: place the source code for the GO dependency packages; GoCoding\ SRC: place the code directory for yourself or your test project
  2. Configure the path of the two folders and the corresponding bin to the environment variable in sequenceGOPATHCreate system variable GOPATH and set it to:C:\GoWorks\DepSource; C:\GoWorks\GoCoding; C:\GoWorks\DepSource\bin; C:\GoWorks\GoCoding\bin;Change the drive letter by yourself
  3. will%GOPATH%Configure to system variablespathIn the

At home, the computer was reconfigured. Go was installed on disk D and GOPATH was configured on disk E, as shown in the picture below

  • folder
  • The environment variable

3. Install the package managergodep

3.1 download

  1. Get the GODEp package:go get -v github.com/tools/godep-v Displays log output. -u Updates to the latest version
  2. View after downloadingC:\GoWorks\DepSource\bin\godep.exeCheck whether godep.exe exists. If yes, the installation is successful
  3. According to theGodeps\Godeps.jsonConfigure the restore dependency package

If you have Godeps\ godeps.json in your project, you can use godep get to install the required dependency packages

3.2 Generate a dependency profile for the GO project

  1. Create a new go project oneGo(GoCoding\ SRC \ oneGo)main.goFile, and introduce a test package, and open CMD to the current path
    package main
    
    import (
        test "github.com/yimogit/gotest"
    )
    
    func main(a) {
        test.HelloWord()
    }
    
    Copy the code
  2. Install test package:go get -v github.com/yimogit/gotest
  3. Build dependency configuration:godep save
  4. Success, if successful, see the oneGo folder generatedGodeps, vendorfolder
  5. Run:go run main.go, the console outputHello Word
  6. Package exe is usedgo build -o test.exe

4. There will be some dependency packages that need to be manually installed when installing GO Framework GIN

Godep save builds the dependency configuration file. The first time you use this command, you will get a bunch of errors about the missing github.com/*/* package. Package (golang.org/x/sys/unix) not found, i.e., when downloading the Package from Golang.org fails (I’m not saying if you succeed), you need to change the path to download it from GitHub. Create a new golang.org\x folder in the GOPATH path (C: GoWorks\DepSource\ SRC) and then clone or download the sys package (modify the path) : git clone https://github.com/golang/sys.git C:\GoWorks\DepSource\src\golang.org\x\sys If the installation fails, run the clone command to download the package to the github.com folder and run the go get github.com/x/x command to install the package

5. Vscode uses dependency packages to be installed

Install the extensions: vscode-go Install dependencies: You can follow vscode’s instructions or directly install the following dependency packages. For more information, see configuring the GO development environment in VScode

go get -u -v github.com/nsf/gocode      
go get -u -v github.com/rogpeppe/godef      
go get -u -v github.com/golang/lint/golint   
go get -u -v github.com/lukehoban/go-find-references   
go get -u -v github.com/lukehoban/go-outline        
go get -u -v sourcegraph.com/sqs/goreturns          
go get -u -v github.com/tpng/gopkgs     
go get -u -v github.com/newhook/go-symbols      
go get -u -v github.com/peterh/liner 
go get -u -v github.com/derekparker/delve/cmd/dlv   
Copy the code