Home>Article>Backend Development> About new usage of golang gopath

About new usage of golang gopath

藏色散人
藏色散人 forward
2021-04-14 10:07:39 2216browse

The following tutorial column will introduce you to the new usage of golang gopath. I hope it will be helpful to friends in need!New usage of golang gopath

Requirements

First of all The project structure I want to achieve is to have a separate directory to store third-party open source libraries, and then my own multiple golang projects can share these open source libraries.

In addition, I don’t want to set the global gopath directory every time I switch projects.

Implementation method


I am using a mac environment. For other environments, please study the configuration method yourself. It should be similar.

First set the environment variables

vi ~/.bash_profile
export GOPATH=/work/go/gopath

Only set the shared third-party open source library storage directory here, and the third-party libraries installed by go get will be stored here

In When compiling the project, manually add the project and directory after GOPATH

echo $GOPATH

/work/go/gopath

export GOPATH=$ GOPATH:/work/go/loolgame

echo $GOPATH

/work/go/gopath:/work/go/loolgame

The project directory must be shared After the open source directory

Finally execute the compilation command

go install server

How to set it under the compiler

In the compiler environment we can set the gopath environment in the compiler To achieve the same purpose as above

intelij IDEA

Configuration environment

Compile

About new usage of golang gopath

go get golang.org/x/net Installation failure solution

About new usage of golang gopathInstallation command: go get golang.org/x/net, error message: package golang.org/x/net: unrecognized import path "golang.org/x/net", package document address: https://godoc.org/golang.org/....

This problem is mainly because golang.org is blocked and cannot be accessed

The simple solution is

Download from https://github.com/golang/net, and then change the directory to golang .org/x/net. Then, everything is fine.

ps: If you have git, you can directly go get github.com/golang/net. If not, you can download it manually and put it in the src directory.


About new usage of golang gopath

The above is the detailed content of About new usage of golang gopath. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete