Go build a development environment IntelliJ IDEA

This article describes Windows7 x64-based IntelliJ IDEA development environment to build the Go language. Some operations are mainly simple text description and screenshots process, if any ambiguities, please correct me. All software (2016.12.02) The latest version, the old version or the new version might be slight differences in the current.

First, the network proxy software cntlm
download the latest version 0.92.3 cntlm from here. cntlm role is to facilitate the implementation go get in Windows. Follow these precautions and keep listening to the default port 3128, other specific installation and configuration reference "within cntlm network proxy agent."
Precautions:

  1. There ensure cntlm.ini following configuration items
    Username <job number>
    the Domain China
    the Auth the NTLM
    PassNT <actual configuration>
    PassLM <actual configuration>
    the Proxy XXXX: 8080
    . NoProxy localhost, 127.0.0 , 10. The , 192.168 *.
    The Listen 3128

  2. It must be installed in the default path C: \ Program Files (x86) \ Cntlm, a non-default path there will be problems

  3. Cntlm services under the unstable Windows, sometimes under the need to manually restart the service to restore an unknown reason. I created a cntlm.bat desktop, network access if there is a problem, do cntlm.bat restart next service (cntlm may consider running on Linux or docker, the service would be more stable. I'll put docker run cntlm If you already have a docker environment, you can find me to be mirrored).
    cntlm.bat document reads as follows:
    NET STOP cntlm
    NET Start cntlm

  4. After the installation configuration, remember to start the service, run directly cntlm.bat

Two, Go 1.7.4
download go1.7.4.windows-amd64.msi, leave the default installation path (C: \ Go \), all the way to Next.
Configure the environment variables (right-click Computer -> Advanced System Settings -> Advanced -> Environment Variables):

  1. Add the environment variable GOPATH, is D: \ Codes \ go

  2. The D: \ Codes \ go \ bin added to the PATH, to facilitate the implementation of the program in its catalog

Three, Git v2.11.0.windows.1
download 64-bit Git for Windows Setup, leave the default installation path (C: \ Program Files \ Git ) and all the default configuration, all the way to Next.

Open Git Bash (right-click on the desktop -> Git Bash here), the implementation of Git basic configuration:

  1. Users and mailboxes
    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 do when you export text format conversion and submission
    git config --global core.autocrlf false

  4. Configure network proxy, using the above cntlm services
    git config --global http.proxy 127.0.0.1:3128

  5. Do not check ssl certificate
    git config --global http.sslVerify false

Four, Go command-line tool
article mentioned 10+ command line tool, which is more useful goimports and golint, the following in order to install these tools, for example, other tools for installation, the steps are similar.
golang.org/x FQ warehouse even not be accessed, the general practice is downloaded from the image repository GitHub placed golang.org/x corresponding path, and then perform the installation. Git Bash executed:

  1. 安装 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 install golint (step download golang.org/x/tools depend on the package)
    go get -v github.com/golang/lint/golint

If this fails, troubleshooting steps above and restart cntlm service, open a new Git Bash try; executed successfully generates two executable programs (File Watchers plug-in will be used later).

Note: The development process, dependent on GitHub package can also be used go get downloaded.

Five, IntelliJ IDEA 2016.3
download the free version of IntelliJ IDEA, leave the default installation path, all the way to Next.

After installation, run IDEA:

  1. If you previously installed an older version, configuration options first before inherit; otherwise default to item 2

  2. Choose your favorite skin, the other way Next

6, installation IDEA plug
6.1 plug-in to access the warehouse need to configure the Network Agent (After installing the plugin, you can remove the configuration)

Faced with this dialog all "Accept"

Or the following check boxes

Go and search for and install 6.2 File Watchers, 2 plugins installed after the restart IDEA

6.3 Configuration Plug-Go

6.4 Creating hello project

Project path is not required, it is recommended to put D: \ Codes \ go \ src \ hello

Note: .idea and hello.iml automatically generated by the IDEA and management, do not manually modify.

Create a source file main.go go

Write a simple piece of code, verify the operation

operation result

6.5 Configuration File Watchers plug-
File Watchers is a project level setting, so to operate on the basis of the previous step works on
File -> Settings ... -> Tools -> File Watchers

-w $FilePath$

-set_exit_status $FilePath$

The File Watchers export the configuration stored in the user's home directory

After create a new project, directly into the configuration, avoid duplication configuration (point a button to switch to the user's home directory)

Edited .go file is saved, goimports the code will be formatted (indented here only alignment)

Results are as follows formatted

golint checks programming style (here suggesting variable names do not use an underscore)

Seven, IDEA using
7.1 run configuration

Already there is a configuration item "Build main.go and run" (which is just executed operation generated)

Click the top left corner of "+" button, you can create a new run configuration

Configuration item named hello, hello to run Package package, the executable program storage directory, run the directory is set to D: \ Codes \ go \ bin

Drop-down box to select hello, click the Execute button

Resulting executable file into the specified output directory

7.2 Startup
Left-click the edit box line number position, you can break point, click on the button to start the debugger to debug

IDEA uses a plug-Go comes delve tool for debugging

Click "Debugger" tab you can view the call stack information, variables, etc.

7.3 libraries set
the IDEA Project Go will load the default GOPATH environment variables, GOPATH can configure multiple directories, allows code spread across multiple directories.
On how to organize the code, it is an ongoing subject of debate ...

Although the code is organized and flexible, but there are also troublesome. In the version control system (svn, git), if the code is spread across multiple places, it is easy to drain submitted - on their own environments to run the project, submit missing dependencies in other directories, others can not export the code to run. One way is not to use GOPATH, dependencies and the mechanisms by vendor code in under a unique directory, also submitted to the repository, IDEA works only add the repository export directory (bin / pkg / src parent directory) to "Project libraries" .

Eight, some settings of IDEA
from the File -> Settings ... The Settings window opens

  1. Do not open the last project
    Appearance & Behavior -> System Settings
    removed Startup / Shutdown -> Reopen last project on startup

  2. When you exit without confirming
    Appearance & Behavior -> System Settings
    removed Startup / Shutdown -> Confirm application exit

  3. Remove the spell checker
    Editor -> Inspections
    remove Spelling -> Typo

  4. Show Line Numbers
    Editor -> General -> Appearance
    check Show line numbers

  5. Editor Font
    Editor -> Colors & Fonts -> Fonts

  6. Console Font
    Editor -> Colors & Fonts -> Console Fonts

  7. Newline
    Editor> Style Code
    Line Separator (Files for new new), is preferably set to Unix and OSX (\ n)

  8. Indentation
    Editor -> Code Style -> Go

  9. Terminal
    Tools -> Terminal
    Shell Path is set to "C: \ Program Files \ Git \ bin \ bash.exe" --login -i
    Git Bash provides much more functionality than cmd.exe, wall cracked recommended that the terminal is set to Git bash, the development process can perform many commands in one!

Legacy:
IDEA also supports MacOS and Linux, by X Server can be run remotely on Windows Linux IDEA, easy to debug code on Linux, subsequent re-add.

Guess you like

Origin www.cnblogs.com/jpfss/p/11781430.html