The main contents of this article are as follows:
- Download and install Go
- Configure multiple workspaces, the first to put third-party packages by default, and other put project codes
- Package Manager
godep Installation and use
- Some pits during installation (wall)
- Use go in Vscode
1. Download and install
go
Download the website or golang China download
Default installation to C:\GO , using go version view version:
The current version is: 1.10
2. Create a new workspace
- Create a new two folder
DEPSOURCE\SRC: Place the source of the go dependency package
GOCODING\SRC: The code directory where you put yourself or test your project
- Configure the path of the two folders and the corresponding bin in order to the environment variable
GOPATH , create a new system variable Gopath, and then the value is: the C:\GoWorks\DepSource;C:\GoWorks\GoCoding;C:\GoWorks\DepSource\bin;C:\GoWorks\GoCoding\bin; drive letter should be modified by yourself
- will be
%GOPATH% configured in a system variable path
------------
At home the computer reconfigured, go installed on the D-disk, Gopath configuration to the E-drive, as shown in
- Folder
- Environment variables
3. Install Package Manager
godep3.1 Downloads
- Get GODEP Package:-
go get -v github.com/tools/godep v Show log output-u update to latest version
- Check to see if there is a godep.exe after the download is complete
C:\GoWorks\DepSource\bin\godep.exe and the installation is successful
Godeps\Godeps.jsonrestore dependent packages based on configuration
If you have one in your project Godeps\Godeps.json , you can use the godep get dependent packages that you install
3.2 Generating a dependency profile for a go project
Creating a new Go Project OneGo (gocoding\src\onego), create a main.go file, and introduce a test package and open cmd to the current path
package mainimport ( "github.com/yimogit/gotest")func main() { test.HelloWord()}
- To install a test package:
go get -v github.com/yimogit/gotest
- To build a dependent configuration:
godep save
- Success, if successful, you see a folder created under the OneGo folder
Godeps,vendor
- Run:
go run main.go , the console outputHello Word
The package EXE usesgo build -o test.exe
4. When installing the Go Framework gin there will be some dependencies that require manual installation of some packages
Start the godep save build dependency configuration file, the first time you use this command will report a bunch github.com/*/* of missing package errors, installation can be error diagram list
When godep: Package (golang.org/x/sys/unix) not found it comes to downloading a package from golang.org (if you can count on me not to say), you need to change the path from github to download (wall, then go on GitHub to put a copy ~)
Specific solutions are:
Create a new folder in the previously set Gopath path (C:\GOWORKS\DEPSOURCE\SRC) golang.org\x , and then clone or download the SYS package
Full command (self-modifying path):git clone https://github.com/golang/sys.git C:\GoWorks\DepSource\src\golang.org\x\sys
In the event of a package download failure in the installation process, you can download it directly to the Github.com folder using the Clone command and then execute go get github.com/x/x it to install the
5. Use the dependent packages that need to be installed in Vscode
Installation extension: Vscode-go
Installation dependencies: You can configure the Go development environment in Vscode by following the Vscode prompts or by installing these dependent packages directly.
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
Development environment Configuration and multi-workspace configuration for Windows go