Ethereum go-ethereum project source code local environment construction

If you want to have an in-depth understanding of the implementation and mechanism of the go-ethereum project, it is essential to look at the source code. Today's blog will briefly introduce how to build the development environment of the project locally.

GO language environment construction

Take win8 as an example, visit the address https://golang.org/dl/ to download the windows version. Execute the installation directly, it will be installed in the C:\Go directory by default, and add the c:\Go\bin directory to the PATH environment variable.
Execute the command to verify that the installation configuration is successful:

C:\Users\Administrator>go version
go version go1.7.4 windows/amd64

development ide

This blog takes Intellij idea 15 as an example.
First install the go language plugin (address https://github.com/go-lang-plugin-org ). Enter the idea's settings, select plugins, Browse repositories, and search for go lang. The specific operation is as follows:
write picture description here

Click install to install Go Lang Plugin. The above picture is for reference only, because the idea in the screenshot has already installed the plug-in. If you cannot download directly, you can configure the address in Manager repositories: https://plugins.jetbrains.com/plugins/alpha/5047
and try to download again. If you cannot download due to network reasons, consider searching for go lang at https://plugins.jetbrains.com to find the plug-in (note that the version is the same as the one in the plug-in) and download the file directly to the local, then import it into idea, and restart the plug-in after installation is complete. Can.

Create a go project

After installing the plugin, create a project in idea, and the Go language project will be displayed. Select the project and configure the SDK to the root directory of the Go installation.

import project

Download the project

Through the git client, download the go-ethereum project on github ( https://github.com/ethereum/go-ethereum.git ).

Directory Structure

At this point, if you import the project directly into idea, you will find that there are many errors. This is because go-ethereum has certain requirements on the project's directory.
The basic directory structure needs to follow the following paths:

-bin(可省略)

-pkg(可省略)

-src

   -github.com

      -ethereum

       -go-ethereum

       -project2(其他项目)
   -golang.org

Therefore, put the downloaded go-ethereum in the specified hierarchical location according to the directory requirements. Then import the project.

Import project and configuration

After importing the project, when opening a go file, idea will prompt to configure the SDK and Configure Go Libraries. The SDK configuration can directly find the root path of the go language or the previous configuration.

Configure Go Libraries, click this prompt to enter the configuration options, add the current project root path in the Project Libraries below (note that it is the upper directory of the above directory structure src), and click OK to complete the GOPATH configuration. The related files of GOPATH will be displayed in the external libraries of the project.

import dependencies

After completing the above steps, such as opening interface.go, you will find that the import "golang.org/x/net/context"is red.
Use the shortcut key alt+enter, you will be prompted to execute the go get command. After clicking Enter, idea will help to add the relevant dependencies to the project.
At this point, looking back at the above directory structure, there will be a golang.org directory at the same level as github.com, and the content of this directory is the dependency content just downloaded.

Summarize

This blog is just a simple introduction, and there are many pits that need to be stepped on by yourself. The pits I have stepped on have also been shared, and there are problems to discuss together.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325389418&siteId=291194637