当前位置:网站首页>Go language notes (4) go common management commands
Go language notes (4) go common management commands
2022-07-04 20:48:00 【fiveym】
Introduce
stay Go In language , Many of our operations are through go Order to proceed , For example, we need to implement go File compilation , You need to use go build command , except build Besides the command , There are also many commonly used commands , This time we will make a unified introduction , Have an understanding of common commands , In this way, we can more easily develop our Go Procedure .
Secondary title
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]``` ## go bulid go build , It can start compilation , Compile our package and related dependencies into An executable file . If it is main package , perform go build after , An executable file will be generated in the current directory . Example : ```go
// Compile the current directory as an executable
go build
// Compile the current directory as an executable
go build .
// compile hello.go The file is an executable
go build hello.g
If go bulid Report errors
/usr/lib/go-1.10/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-008006128/000026.o: In function _cgo_05dc84caff82_Cfunc_sysconf': /tmp/go-build/cgo-gcc-prolog:32: multiple definition of_cgo_05dc84caff82_Cfunc_sysconf’ /tmp/go-link-008006128/000024.o:/tmp/go-build/cgo-gcc-prolog:32: first defined here collect2: error: ld returned 1 exit status
resolvent :
linux: export CGO_ENABLED=0
windows : cmd: set CGO_ENABLED=0
windows : powershell:$env:CGO_ENABLED=0
go run
go bulid Compile first , Then we need two steps to execute the executable file to execute our program
go run This command is the command that can combine these two steps into one step , Save us the time of entering
Command format :
```go
go run file name .go
Example :
go run main.go
go install
go install Command and go bulid Commands are similar to those used to generate project executables , But it compiles , Install the generated executable file or library into the corresponding directory , For use .
Install the executable to : $GOPATH/bin/
Referential libraries installed to : $GOPATH/pkg/
Be careful : It's not turned on go mod when , You need to configure... To use the above command GOPATH, Otherwise it will be reported :no install location.
go get
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.
go get In essence, it can be understood as through source code tools clone After code , Yes go install.
Command format :
Download package : add to -u Parameters can automatically update packages and dependencies
go get github.com/**/**
Use the installed package
import "github.com/****/****"
If the download is slow , Remember to configure goproxy
// Set up module management model
$ go env -w GO111MODULE=on
// Set download source
$ go env -w GOPR
go fmt
go fmt Command can format code files
Use go fmt command , It's actually called gofmt, And you need parameters -w, Otherwise, the formatting result will not be written to the file
// Command format :
go fmt -w file name .go
// Example : Format the entire project
gofmt -w -l src
// Common parameters :
-l: Those files that need to be formatted
-w: Write the rewritten content directly into the file , Instead of printing as a result to standard output .
-r: Add shapes like "a[b:len(a)] -> a[b:]" The rewriting rules of , It is convenient for us to make batch replacement
-s: Simplify the code in the file
-d: Displays the before and after formatting diff Instead of writing to a file , The default is false
-e: Print syntax errors to standard output . Without this parameter, only the front of different lines will be printed 10 A mistake .
go tool
go tool There were a lot of orders , There are mainly 2 individual , namely fix and vet:
go tool fix .: Used to fix the old version of the code to the new version
go tool vet directory|files: Analyze whether the code of the current directory is correct
边栏推荐
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
- Flet教程之 06 TextButton基础入门(教程含源码)
- 分析伦敦银走势图的技巧
- Jekins initialization password not found or not found
- LeetCode 8. 字符串转换整数 (atoi)
- 【深度学习】一文看尽Pytorch之十九种损失函数
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- Why is the maximum speed the speed of light
- So this is the BGP agreement
- BFC面试简述
猜你喜欢

Reinforcement learning - learning notes 2 | value learning

九齐NY8B062D MCU规格书/datasheet

Qt五子棋人机对战画棋子之QPainter的使用误区总结

Alibaba testers use UI automated testing to achieve element positioning
![NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]](/img/79/82763392e74d102921b4e8e601d4c6.png)
NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]

What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system

What if win11u disk refuses access? An effective solution to win11u disk access denial

面对同样复杂的测试任务为什么大老很快能梳理解决方案,阿里十年测试工程师道出其中的技巧

Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world

太方便了,钉钉上就可完成代码发布审批啦!
随机推荐
工厂从自动化到数字孪生,图扑能干什么?
Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
记录线上bug解决list(未完待续7/4)
什么是区块哈希竞猜游戏系统开发?哈希竞猜游戏系统开发(案例成熟)
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Automatic insertion of captions in word
Flet tutorial 04 basic introduction to filledtonalbutton (tutorial includes source code)
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
Record the online bug solving list (unfinished to be continued 7/4)
NetCore3.1 Json web token 中间件
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
word中插入图片后,图片上方有一空行,且删除后布局变乱
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
LeetCode 7. 整数反转
How to solve the problem that win11 cannot write the value to the registry key?
#夏日挑战赛#带你玩转HarmonyOS多端钢琴演奏
Integretee integrates into Moonriver through xcm, bringing enterprise class privacy solutions to its ecosystem
FS4061A升压8.4V充电IC芯片和FS4061B升压12.6V充电IC芯片规格书datasheet
Win11无法将值写入注册表项如何解决?
Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)