Introduction to three ways to introduce external dependencies in go

Release: 2020-03-02 15:57:21
forward
7146 people have browsed it

Introduction to three ways to introduce external dependencies in go

import "github.com/astaxie/beego" Compilation error solution:

go get

Make sure your GOPATH is the project directory, the code is in the src directory, and then enter: go get github.com/astaxie/beego in the command prompt, and then the external package to be introduced is generated under the local src.

Note: When using the GoLand tool, configure settings->Go->GOPATH->Project GOPATH to the current project directory

go module

Go Module can only be used with Go version 1.11 or above. Go Module is turned off by default below version 1.13.

First you need to set the environment variable set GO111MODULE=on, create a new project folder, enter the new path and execute go mod init. Generate the go.mod file in the folder, then place the go file that needs to introduce the external package in the project directory, compile the file, and the external package will be downloaded to the local GOPATH/pkg/mod directory

Note: When using the GoLand tool, do not configure Project GOPATH as the current project directory. It is best not to configure Project GOPATH, but configure Module GOPATH

vendor directory

First Install govendor: go get -u -v github.com/kardianos/govendor. After downloading, configure the environment variable GOPATH/bin and type the command

govendor -version to check whether the installation is successful.

In the directory of GOPATH/src, create a new project folder, enter the new path and execute gogovendor init, vendor/vendor.json will be generated in the folder.

Then place the go file that needs to introduce the external package in the project directory, use the command govendor fetch github.com/golang/glog to download the external file to the local vendor/, and add this in vendor.json Dependent package information, where govendor fetch is to add dependent packages from the remote library, and to add dependent packages from $GOPATH, use govendor add

For more go language knowledge, please pay attention to php Chinese websitego Language tutorial column.

The above is the detailed content of Introduction to three ways to introduce external dependencies in go. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
go
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template