当前位置:网站首页>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
边栏推荐
- How does win11 search for wireless displays? Win11 method of finding wireless display device
- Related concepts of federal learning and motivation (1)
- How to adapt your games to different sizes of mobile screen
- 精选综述 | 用于白内障分级/分类的机器学习技术
- MySQL中的日期时间类型与格式化方式
- See how Tencent does interface automation testing
- Flet tutorial 07 basic introduction to popupmenubutton (tutorial includes source code)
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
- How does the computer save web pages to the desktop for use
- What if the win11 shared file cannot be opened? The solution of win11 shared file cannot be opened
猜你喜欢
Jiuqi ny8b062d MCU specification /datasheet
Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
How to solve the problem that win11 cannot write the value to the registry key?
Alibaba testers use UI automated testing to achieve element positioning
太方便了,钉钉上就可完成代码发布审批啦!
Qt编写物联网管理平台38-多种数据库支持
NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]
关于联邦学习和激励的相关概念(1)
What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system
How does win11 search for wireless displays? Win11 method of finding wireless display device
随机推荐
Jiuqi ny8b062d MCU specification /datasheet
【深度学习】一文看尽Pytorch之十九种损失函数
Qt编写物联网管理平台38-多种数据库支持
Flet教程之 07 PopupMenuButton基础入门(教程含源码)
SSRS筛选器的IN运算(即包含于)用法
Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world
九齐NY8B062D MCU规格书/datasheet
Idea plug-in
奏响青春的乐章
实践示例理解js强缓存协商缓存
The problem of the maximum difference between the left and right maxima
Common verification rules of form components -1 (continuously updating ~)
Automatic insertion of captions in word
FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC
How does win11 search for wireless displays? Win11 method of finding wireless display device
AP8022开关电源小家电ACDC芯片离线式开关电源IC
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
阿里测试师用UI自动化测试实现元素定位
精选综述 | 用于白内障分级/分类的机器学习技术