This is a creation in Article, where the information may have evolved or changed.
This paper introduces Windows7 x64 based on IntelliJ idea to build the Go language development environment. Mainly is some operation procedure as well as the simple text description, if has the unclear place, welcome to correct. All software uses the current (2016.12.02) latest version, there may be minor differences between the previous version or the new edition.
First, network agent software CNTLM
Download the latest 0.92.3 version CNTLM. CNTLM function is convenient to perform go get under Windows. Refer to the following precautions, and keep the listening port as the default 3128, other specific installation and configuration refer to the agent of CNTLM intranet agent.
Precautions:
1) Ensure that Cntlm.ini has the following configuration items
Username < work No. >
Domain China
Auth NTLM
passnt < by actual configuration >
PASSLM < by actual configuration >
Proxy xxxx:8080
Noproxy localhost, 127.0.0. , ten., 192.168.*
Listen 3128
2) must be installed in default path C:\Program Files (x86) \CNTLM, non-default path will be problematic
3) The CNTLM service under Windows is unstable and sometimes requires a manual restart under service recovery for unknown reasons. I created a cntlm.bat on the desktop, and if there is a problem with the network access, perform the Cntlm.bat restart service (consider running the CNTLM in Linux or Docker, the service will be more stable. I'll put CNTLM in Docker, and if you already have a Docker environment, you can look for me to mirror.
The contents of the Cntlm.bat file are as follows:
net stop CNTLM
net start CNTLM
4) After the installation of the configuration, remember to start the service, you can directly run Cntlm.bat
Second, Go 1.7.4
Download Go1.7.4.windows-amd64.msi, keep the default installation path (C:\Go\), all the way Next.
Configure environment variables (right-click Computer, advanced system settings, advanced environment variables):
1) Add environment variable Gopath, value is D:\Codes\go
2) Add D:\Codes\go\bin to PATH for easy execution of programs under its directory
Third, Git V2.11.0.windows.1
Download 64-bit Git for Windows setup, keep the default installation path (C:\Program files\git) and all the default configurations, all the way Next.
Open git bash (on the desktop right-click Git bash here) to perform the GIT basic configuration:
1) User and mailbox
git config--global user.name XXXX
git config--global user.email XXXX
2) Support Long Path
git config--global core.longpaths true
3) do not convert text format when exporting and submitting
git config--global core.autocrlf false
4) Configure the network agent to use the above CNTLM service
git config--global http.proxy 127.0.0.1:3128
5) Do not verify the SSL certificate
git config--global http.sslverify false
Four, Go command line tools
This article refers to the more than one command-line tool, which is more useful goimports and Golint, the following to install the two tools, for example, to install additional tools, similar steps.
golang.org/x Warehouse Even if FQ is not accessible, the general practice is to download from the GitHub Mirror repository, place it in the golang.org/x corresponding path, and then perform the installation. Git Bash Execution:
1) Install Goimports
Export gopath= "D:\Codes\go"
git clone https://github.com/golang/tools.git $GOPATH/src/golang.org/x/tools
Go Install Golang.org/x/tools/cmd/goimports
2) use go get to install Golint (dependent on the Golang.org/x/tools package that was downloaded in the previous step)
Go get-v github.com/golang/lint/golint
If the execution fails, troubleshoot the above steps and restart the CNTLM service, open a new Git Bash, and the execution will generate two executables (which the File watchers plugin will use later).
Note: The development process, depending on the GitHub package, can also be downloaded using go get.
V. IntelliJ Idea 2016.3
Download IntelliJ idea free version, keep the default installation path, all the way Next.
After installation, run idea:
1) If you have previously installed an older version, select 1th before inheriting the configuration, or default 2nd
2) Choose your favorite skin, other all the way Next
VI. Install IDEA Plugin
6.1 Access to the plug-in warehouse needs to configure the network proxy (after installing the plug-in, you can remove the configuration)
Encounter such a dialog box is "Accept"
or tick the check boxes below
6.2 Search and install Go and File watchers,2 plugins after installation restart idea
6.3 Configuring the Go Plugin
6.4 Creating a Hello Project
Project path is not required, it is recommended to put it in D:\Codes\go\src\hello first
Note: Idea and HELLO.IML are automatically generated and managed by idea, not manually modified.
Create a Go source file Main.go
Write a simple code to verify that the operation is working properly
Run results
6.5 Configuring the File watchers Plugin
File watchers is a project-level setup, so work on the previous project
FILE--Settings-Tools--watchers
-W $FilePath $
-set_exit_status $FilePath $
Export the file watchers configuration to the user's home directory
Create a new project later, import the configuration directly, avoid duplicate configuration (click the 1th button to switch to the user home directory)
After editing the. Go file, Goimports will format the code (indented only)
After formatting the effect is as follows
Golint will check the programming style (the variable name is not underlined here)
Vii. use of Idea
7.1 Run Configuration
A configuration item "Build Main.go and run" already exists (this is the run-generation that was executed just now)
Click the "+" button in the top left corner to create a new run configuration
The configuration item is named Hello, which runs the Hello package, executes the program's directory, and runs the directory set to D:\Codes\go\bin
Drop-down box select Hello, click the Execute button
The resulting executable file is placed in the specified output directory
7.2 Commissioning
Left mouse click edit box line number position, you can break point, click the Debug button to start debugging
Idea uses the Delve tool from the Go plugin to debug
Click on the "Debugger" tab to view the call stack, variables and other information
7.3 Libraries Settings
Idea's Go project loads the GOPATH environment variable by default, Gopath can configure multiple directories, allowing the code to be scattered across multiple directories.
The topic of how to organize code is an ongoing debate ...
Although the code is organized in a flexible way, there are also problems. In the version control System (SVN,GIT), if the code is scattered in multiple places, it is easy to miss commits-works that are able to run on their own environment, omit the dependency packages from other directories, and the code exported by others cannot run. One way is to not use Gopath, the dependency package through the vendor mechanism and code in the unique directory, also submitted to the repository, the idea project only add the Repository export directory (bin/pkg/src parent directory) to "Project Libraries".
Viii. Some settings for idea
From File--Settings ... Open the Settings window
1) do not open the last project
Appearance & Behavior, System Settings
Remove Startup/shutdown-Reopen last project on Startup
2) No need to confirm when exiting
Appearance & Behavior, System Settings
Remove Startup/shutdown-Confirm application exit
3) Remove spell check
Editor, inspections
Remove Spelling-Typo
4) Display line number
Editor, General, appearance
Tick Show line Numbers
5) Editor Font
Editor, Colors & Fonts-Fonts
6) Console Font
Editor, Colors & Fonts, Console Fonts
7) Line break
Editor > Code Style
Line Separator (for new files), preferably set to Unix and OSX (\ n)
8) Indent format
Editor, Code Style, Go
9) Terminal
Tools-Terminal
The Shell Path is set to "C:\Program Files\git\bin\bash.exe"--login-i
Git bash offers much more functionality than Cmd.exe, and wall splitting suggests setting the terminal to Git Bash, where the development process can execute many commands!
Legacy:
Idea also supports MacOS and Linux, and with X Server it is possible to run Linux idea remotely in Windows to easily debug code on Linux and add to it later.