go常用命令

创建一个module(逻辑概念)
#The go mod init command initializes and writes a new go.mod file in the current directory, in effect creating
#a new module rooted at the current directory.
#specify a module path that serves as the module’s name.
go mod init

clone一个项目之后,不要使用go get去下载依赖(因为会默认下载最新版本),使用go mod tidy会下载go.mod文件中的指定版本
#go mod tidy ensures that the go.mod file matches the source code in the module.
#It adds any missing module requirements necessary to build the current module’s packages and dependencies,
#and it removes requirements on modules that don’t provide any relevant packages.
#It also adds any missing entries to go.sum and removes unnecessary entries.
#增加丢失的module依赖,移除没有被使用的module依赖(项目中没有使用该module依赖提供的任何包)
go mod tidy

#You can check to see if there are newer versions of dependencies you’re already using in your current module.
go list -m -u all

go clean -cache#清除编译产生的缓存
go clean -modcache#清除下载的module依赖

#compiles and installs the packages
#Executables(main packages)被安装到GOBIN目录下(默认是$GOPATH/bin).
#Non-executable packages are built and cached but not installed.
#main packages are built into executables and non-main packages are built into .a files.
go install package_path
go install golang.org/x/tools/gopls#安装当前module指定的版本

go help clean,modules
go env# 查看配置信息
go env -w GOPROXY=https://goproxy.cn,direct#设置module proxy server为国内的,提高下载速度
#将同属于一个package的源文件编译为目标文件.o或者是package archive(packagefile).a文件
go tool compile -d help

#go文件,没有参数,module path
go build -v -o demo.exe demo_pro
go build -gcflags -help
增加,移除,升级,降级某个module依赖,同时也会更新go.mod文件
#In Go 1.18, go get will no longer build and install packages.
#It will only be used to add, update, or remove dependencies in go.mod.

go get package_path/module_path
参数:某个module或者某个module的一个package
参数为package_path时,go get会下载/更新提供这个包的module(更新就是升级到最新版本)
#If a package argument is specified, go get updates the module that provides the package.
#If an argument names a module but not a package(for example, the module golang.org/x/net has no package in its root
#directory), go get will update the module.
-u:升级command line上的package所依赖的module
#The -u flag tells go get to upgrade modules providing packages imported directly or indirectly by packages named
#on the command line.

#升级/降级module依赖
go get golang.org/x/net#Upgrade a specific module.
go get golang.org/x/text@v0.3.2#Upgrade or downgrade to a specific version of a module.

#移除这个module依赖,并且将依赖它的其他module依赖降级到不再依赖它
#Remove a dependency on a module and downgrade modules that require it to versions that don't require it.
go get golang.org/x/text@none

https://github.com/golang/go/issues/46912
https://pkg.go.dev/cmd@go1.22.3
https://pkg.go.dev/cmd/compile@go1.22.3
https://pkg.go.dev/cmd/go
https://stackoverflow.com/questions/69465514/what-is-the-difference-between-compile-and-build-in-go
https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/cmd/compile/;bpv=0

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值