当前位置:网站首页>Common commands and package management of go language
Common commands and package management of go language
2022-07-24 06:34:00 【Laughter addiction】
Common commands
One 、 Common command summary
go version: obtain Go edition
go env: see Go environment variable
go help: see Go Help order
go get: Get remote package ( It needs to be installed in advance git or hg)
go build: Compile and generate executable programs
go run: Run the program directly
go fmt: Format source code
go install: Compile the package file and the whole program
go test: go Unit test commands provided by native
go clean: Remove the files compiled and generated in the current source package and the associated source package
go tool: upgrade Go version , Fix old code
godoc -http:80: Open a local 80 Port of web file
gdb Executable name : debugging Go Compiled file
Use format :
go command [arguments]
Two 、 Detailed explanation of common commands
1、go build
1、go build , It can start compilation , Compile our package and related dependencies into An executable file .
2、 If it is main package , perform go build after , An executable file will be generated in the current directory .
3、 demonstration :
// Compile the current directory as an executable
go build .
// compile hello.go The file is an executable
go build hello.go
2、go run
1、go build Compile first , Then we execute the executable file to run our program , Two steps are needed. .
2、go run This command is the command that can combine these two steps into one step , It saves us the time of entering 
3、go get
1、go get It is used to get the package in the remote warehouse , You must configure... Before using this command GOPATH, And according to different source websites , Also install different version management tools , For instance from github Upper use go get Additional installation required git.
2、go get In essence, it can be understood as through source code tools clone After code , Yes go install.
go Package management
One 、go Three kinds of package management
Recommended choice go module Package management mode of
go path
stay 1.5 Before the release , All dependent packages are stored in GOPATH Next , No version control .
The biggest disadvantage of this method is that it can not realize multi version control of packages , For example, projects A And projects B Depends on different versions of package, If package Not fully forward compatible , It often leads to some problems .
go vendor
1.5 Version launched vendor Mechanism . So-called vendor Mechanism , There can be one in the root directory of each project vendor Catalog , It stores the dependencies of the project package. go build I'll go first vendor Directory lookup dependency , If you don't find it, you'll go again GOPATH Directory lookup .
go module
1.11 Version launch modules Mechanism , abbreviation mod. The mode was passed mod.go File management dependencies
Two 、go The pre knowledge inside
1、 Two commands
Installing binary executables is recommended go install
go install xxx ( install xxx Third party binary executables )
go install similar go build , Put the generated executable into 【$GOPATH/bin】 Directory
go get xxx ( download xxx Third parties rely on packages and install )
go get Yes download and install , namely git clone + go install , take clone The source code of 【$GOPATH/src】 in
2、 Two paths
GOROOT:go Installation directory , similar java Of jdk, Store some built-in development packages and tools .
GOPATH:go The specified workspace is used to save go Project code and third-party dependency packages .
3、 ... and 、go mod Use of commands
1、go help mod View relevant help commands 、
2、go mod Common commands
go mod init: initialization modules
go mod download: download modules To local cache
go mod edit: edit go.mod file , Option has -json、-require and -exclude, You can use help go help mod edit
go mod graph: Print module requirement diagram in text mode
go mod tidy: Check , Delete the wrong or unused modules, Did you download it download Of package
go mod vendor: Generate vendor Catalog
go mod verify: Verify that the dependency is correct
go mod why: Find dependencies
go test Execute it. , Automatic guiding package
go list -m Print path of main module
go list -m -f={
{.Dir}} print The root directory of the main module
go list -m all View the current dependency and version information
边栏推荐
- leetcode剑指offer JZ23:链表中环的入口节点
- RAID5 and LVM are used in combination
- 常用工作方法总结(7S、SWOT分析、PDCA循环、SMART原则、6W2H、时间管理、WBS、二八原则)
- 联合国农产品数据分析
- JSP tag 02
- 项目上复盘引导问题清单
- [no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
- How to build a website full of ritual sense and publish it on the public website 1-2
- mysql 忘记退出直接关闭窗口现在要删除整个文件夹如何删除
- [251] common test tools
猜你喜欢

Polkadot | interprets how liberty plan, which subverts traditional social media, will be launched in Poka

Website B video is embedded in the web page, and relevant controls are hidden

JSP tag

sed命令

Crud of MySQL

IP class notes (4)

日志收集分析平台

XML parsing
![[214] what is an automation framework](/img/bb/24c35613c49357258876ce3f1611ee.jpg)
[214] what is an automation framework

PXE technology network installation
随机推荐
Rsync (I): basic commands and usage
自定义zabbix agent rpm包
Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
RAID5 and LVM are used in combination
Life warning Maxim
Grid layout
CentOS操作系统安全加固
Maximum value of jz47 gifts (dynamic planning ideas)
Leetcode refers to offer jz5 to replace the space string
Map the intranet to the public network [no public IP required]
Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
[226] instructions for Wireshark parameters
Leetcode sword finger offer jz42 maximum sum of continuous subarrays
[251] common test tools
IP job (6)
go语言常用命令和包管理
【218】CS架构和BS架构以及数据放在服务端和客户端的利与弊?
Login page + summary
[219] what is the difference between app testing and web testing?
联合国农产品数据分析