Windows Visual Studio Code builds the Golang development environment

Source: Internet
Author: User
Tags windows visual


Objective


In fact, the environment is not difficult to build, but encountered some problems, mainly some site resources can not access (such as: golang.org),
Cause some packages can not be installed, will eventually lead to environmental failure, with this tutorial a few steps, we will be able to quickly build the Golang development environment.


Development environment:




First, installation


Here I need to install some tools:



1.Visual Studio Code 1.0.0



2.Golang Downloads


Here I am using Go1.6.


3.git Downloads


This step has nothing to do with building the environment, but it is necessary to reference some packages later.


4. Installing the Vscode-go Plugin





Installation method: Open vscode, press F1 and select install extension. Select go download and restart.





5. Download the Vscode extension Dependency tool


The vscode-go plugin requires some tools that need to be installed by default:

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-outline
Go get -u -v sourcegraph.com/sqs/goreturns
Go get -u -v golang.org/x/tools/cmd/gorename
Go get -u -v github.com/tpng/gopkgs
Go get -u -v github.com/newhook/go-symbols
Go get -u -v golang.org/x/tools/cmd/guru
(and the dlv debug run tool)

The ultimate goal of this content is to generate some exe files in the bin folder in the gopath.
However, there are some problems encountered during the installation. Some of them will fail to install. The main reason for the error message is that you can't link, you can't find it.
Here I am omitting these steps. Directly download the exe package I have generated, and put it in the bin folder of the gopath. Such as:




Second, the configuration


1.GOPATH: This is your working directory, please specify your working directory in the system with a new gopath, and create a new one in the working directory
BIN,PKG,SRC of three folders.



2.Git: Add the Bin directory under the Git installation directory to the PATH environment variable.



3. Open the SRC folder with Vscode to add two files as follows:


{
    "files.autoSave": "onFocusChange",
    "go.buildOnSave": true,
    "go.lintOnSave": true,
    "go.vetOnSave": true,
    "go.buildTags": "",
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.coverOnSave": false,
    "go.useCodeSnippetsOnFunctionSuggest": false,
    "go.formatOnSave": true,
    "go.formatTool": "goreturns",
    "go.goroot": "C:\\Go",
    "go.gopath": "H:\\Projects\\GitHub\\Go",
    "go.gocodeAutoBuild": true
}




{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${workspaceRoot}\\helloworld",
            "env": {},
            "args": []
        }
    ]
}
Third, the demo run




Debugging




Iv. Summary


These libraries because can not get, I found on GitHub for a long time, finally compiled into EXE, the domestic find a few articles mentioned this problem,
So write a blog, let everyone convenient development. I hope you will enjoy learning the go language.






Turn:



Windows Visual Studio Code builds the Golang development environment


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.