当前位置:网站首页>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
边栏推荐
- Hash quiz game system development how to develop hash quiz game system development (multiple cases)
- 【深度学习】一文看尽Pytorch之十九种损失函数
- What is involution?
- From automation to digital twins, what can Tupo do?
- Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
- Talking about cookies of client storage technology
- Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
- AP8022开关电源小家电ACDC芯片离线式开关电源IC
- Function analysis and source code of hash guessing game system development
- idea配置标准注释
猜你喜欢
![[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born](/img/0b/73f0d98a6db813e54074abe199ed98.png)
[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born

Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法

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

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

Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法

Flet教程之 06 TextButton基础入门(教程含源码)

So this is the BGP agreement
一文搞懂Go语言中文件的读写与创建
Practice examples to understand JS strong cache negotiation cache

Idea configuration standard notes
随机推荐
看腾讯大老如何做接口自动化测试
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
Four traversal methods of binary tree, as well as the creation of binary tree from middle order to post order, pre order to middle order, pre order to post order, and sequence [specially created for t
NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]
九齐NY8B062D MCU规格书/datasheet
word中插入图片后,图片上方有一空行,且删除后布局变乱
Six stones programming: about code, there are six triumphs
Huawei cloud store homepage banner resource bit application
go笔记(1)go语言介绍以及特点
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
From automation to digital twins, what can Tupo do?
Flet tutorial 04 basic introduction to filledtonalbutton (tutorial includes source code)
太方便了,钉钉上就可完成代码发布审批啦!
MySQL statement execution details
go笔记(3)Go语言fmt包的用法
什么叫内卷?
NetCore3.1 Json web token 中间件