当前位置:网站首页>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
边栏推荐
- 二叉树的四种遍历方式以及中序后序、前序中序、前序后序、层序创建二叉树【专为力扣刷题而打造】
- Flet教程之 06 TextButton基础入门(教程含源码)
- How to solve the problem that win11 cannot write the value to the registry key?
- Jekins initialization password not found or not found
- tcp为啥是三次握手和四次挥手
- Flet教程之 05 OutlinedButton基础入门(教程含源码)
- Six stones programming: about code, there are six triumphs
- jekins初始化密码没有或找不到
- Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
猜你喜欢

What should I do if my computer sharing printer refuses access

电脑页面不能全屏怎么办?Win11页面不能全屏的解决方法

Idea configuration standard notes
![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]
![[in-depth learning] review pytoch's 19 loss functions](/img/c1/07650a6755d5c64ebf8ce370456fb7.png)
[in-depth learning] review pytoch's 19 loss functions

关于联邦学习和激励的相关概念(1)

工厂从自动化到数字孪生,图扑能干什么?

黄金k线图中的三角形有几种?

How does the computer save web pages to the desktop for use

伦敦银走势图分析的新方法
随机推荐
Hash quiz game system development how to develop hash quiz game system development (multiple cases)
哈希(Hash)竞猜游戏系统开发功能分析及源码
What if the computer page cannot be full screen? The solution of win11 page cannot be full screen
Length of the longest integrable subarray
CDGA|数据治理不得不坚持的六个原则
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
Win11无法将值写入注册表项如何解决?
From automation to digital twins, what can Tupo do?
jekins初始化密码没有或找不到
字节测试工程师十年经验直击UI 自动化测试痛点
黄金k线图中的三角形有几种?
Stack: how to realize the judgment of valid brackets?
Après l'insertion de l'image dans le mot, il y a une ligne vide au - dessus de l'image, et la disposition est désordonnée après la suppression
【深度学习】一文看尽Pytorch之十九种损失函数
电脑页面不能全屏怎么办?Win11页面不能全屏的解决方法
记一次 .NET 某工控数据采集平台 线程数 爆高分析
被奉为经典的「金字塔原理」,教给我们哪些PPT写作技巧?
Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
js 闭包
word中使用自动插入题注功能