当前位置:网站首页>About the use of go modules environment construction and package management tools
About the use of go modules environment construction and package management tools
2022-07-18 23:54:00 【Little Harry】
List of articles
1 GOPATH
Go Dependency management of has mainly experienced 3 Stages , Namely GOPATH, GoVendor, Go Module.
The whole evolution route is mainly developed iteratively around the realization of two goals , Namely 1,2
GOPATH yes Go An environment variable supported by the language ,value yes Go Project workspace .
The directory has the following structure :
src Deposit Go Project source code ;
pkg: Store the intermediate products of compilation , Speed up compilation ;
bin: Deposit Go The second lecture system file generated by the project compilation .
use gopath What are the disadvantages of relying on Management ? I believe everyone has their own thinking results , Let me have a look , The same ke , Yes 2 A version ,A->A468, B-EC0 and src There can only be one version under ,AB There is no guarantee that it will compile , That is to say gopath Under management , If there are multiple projects that depend on this library, it is the same code , Different projects cannot rely on different versions of the same library , This obviously does not meet our project dependency requirements . To solve this problem ,govender There is .
# Enter the following command on the command line to view Go Configuration information
go env

GOARCH Represents the target processor architecture .
GOBIN Indicates where the compiler and linker are installed .
GOOS Represents the target operating system .
GOPATH Represents the current working directory .
GOROOT Express Go Installation directory of development package .
How to modify GOPATH
windows default directory %USERPROFILE%\go
Add, delete, modify and check directly in the environment variable .
2 GoVendor
- Vendor Is a directory in the current project , It stores the version of the current project . stay Vendor Hu zhixia , If the current project exists Vendor Catalog , The dependencies in this directory will be used preferentially , If dependency does not exist , From (GOHATH Search for )
3 Go Module
- GoModues yes Go The dependency management system officially launched by the language , It solves the problems existing in the previous dependency management system, such as being unable to rely on multiple versions of the same library go mocdue from Go 11.1 Start experimental introduction ,Go 1.16 Default on ;
How to view Go edition
go version
- Set up go mod and go proxy
go env -w The configuration will be written to GOENV=“/Users/youdi/Library/Application Support/go/env”
Go Modules Environment configuration
go env -w GOBIN=/Users/gwj11/go/bin
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct // Use seven cow cloud
- GO111MODULE=off,go The command line will not support module function , Looking for dependency packages will follow the old version through vendor Catalog or GOPATH Pattern to find .
GO111MODULE=on,go Command guild Use modules, And not at all GOPATH Directory lookup .
When modules When the function is enabled , The storage location of the dependency package is changed to $GOPATH/pkg, Allow the same package Multiple versions coexist , And multiple projects can share the cache module
4 An example
First, we need to initialize a go.mod
go mod init test
Then when we introduce the module , With test( Define... At initialization time ) start , Then connect the module path , such as
import "test/module"
Create a new one hello.go The documents are as follows
package main
import "github.com/astaxie/beego"
func main() {
beego.Run()
}
Follow past practice , To run hello.go You need to perform go get command download beego Package to $GOPATH/src
Now we can directly go run hello.go
Wait a moment … go Will automatically find the package in the code , Download dependency package , And write specific dependencies and versions to go.mod and go.sum In file .
module Gone
go 1.14
require github.com/gin-gonic/gin v1.6.3
see go.mod, It's going to be like this :
module hello
go 1.12
require github.com/astaxie/beego v1.11.1
- Where are the dependent packages downloaded ? still GOPATH Li ?
be not in . Use Go Package management mode of , The dependent third party package has been downloaded to $GOPATH/pkg/mod
边栏推荐
- Ngrx store state management
- nodejs 定义错误验证机制
- Google icons library compose can be used directly.
- 利用备份恢复数据库,但是没有控制文件文件如何解决
- Redis分布式缓存-Redis主从
- TCP 糊涂窗口综合症(silly window syndrome)与 rate-based 流控
- Clean the disk with CMD command (mainly the system disk)
- E. Split Into Two Sets
- VMware6.0连接群晖iscsi
- Under dynamic memory management (C language) -- common errors and written examination questions of large factories
猜你喜欢
随机推荐
应用的无状态设计
How to use redis to realize distributed cache
Core principle of buffer pool
STM32F1与STM32CubeIDE编程实例-W25Q-SPI-Flash驱动
微信小程序_14,组件的创建与引用
每日一题:回文链表(剑指off027)
Jedi survive eating chicken 98K does not automatically close the mirror
一组简单多用途表单小部件代码
Expérience de l'arbre binaire
Wechat applet_ 16. Component life cycle
matplotlib.pyplot使用(subplots,gray
[STL] simulation implementation vector
每日一题:合并两个排序的链表(剑指offer25)
Eat chicken, throw away some supplies, and the Jedi survive
P5js coffee cup steaming JS special effect
微信小程序_15,纯数据字段
在安装虚拟机时,”intel vt-x 处于禁用状态“ 如何解决
Pytest interface automation test framework | @pytest Fixture () decorator
nodeJS中利用第三方内置模块实现数字转大写功能
Applet: the picker view selector scrolls quickly. When confirming, the "value displays an error."“









