go_compiler

Resolving a package to a module

bash 复制代码
When the go command loads a package using a package path, it needs to determine which module provides the package.
If no modules provide the package or if two or more modules provide the package, the go command reports an error.
The -mod=mod flag instructs the go command to attempt to find new modules providing missing packages and to update
go.mod and go.sum.
The go get and go mod tidy commands do this automatically.
#通过GOPROXY中的地址下载module依赖
When the go command looks up a new module for a package path, it checks the GOPROXY environment variable, which is
a comma-separated list of proxy URLs or the keywords direct or off.
A proxy URL indicates the go command should contact a module proxy using the GOPROXY protocol.
direct indicates that the go command should communicate with a version control system.
off indicates that no communication should be attempted.
#寻找可能提供此package的module
For each entry in the GOPROXY list, the go command requests the latest version of each module path that might
provide the package (that is, each prefix of the package path).
For each successfully requested module path, the go command will download the module at the latest version and check
whether the module contains the requested package.
If no modules are found, the go command tries the next entry in the GOPROXY list.
#成功找到
After a suitable module has been found, the go command will add a new requirement with the new module's path
and version to the main module's go.mod file.

go.mod文件

bash 复制代码
require指令
#require module-path module-version
#Declares a module as a dependency of the current module, specifying the minimum version of the module required.
#For each required module version, the go command loads the go.mod file for that version and incorporates the
#requirements from that file.
#indirect表示该module中的package没有被项目直接依赖
#An // indirect comment indicates that no package from the required module is directly imported by any package in
#the main module.

compiler

bash 复制代码
gc是Go compiler,GC是garbage collection
go tool compile -h
-gcflags=-lang=go1.22,会将参数传给go tool compile.

The build flags are shared by the build, clean, get, install, list, run, and test commands:
-x,print the commands.(可以查看go build,run,clean的执行细节)
-asmflags,arguments to pass on each go tool asm invocation.
-gcflags,arguments to pass on each go tool compile invocation.
-ldflags,arguments to pass on each go tool link invocation.
The -asmflags, -gccgoflags, -gcflags, and -ldflags flags accept a space-separated list of arguments to pass to an
underlying tool during the build.

https://go.dev/ref/mod

https://go.dev/doc/modules/gomod-ref

https://pkg.go.dev/cmd/go@go1.22.3

https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/cmd/compile/;bpv=0

https://github.com/golang/go/blob/master/src/cmd/compile/README.md

https://www.reddit.com/r/golang/comments/16okuwb/can_you_explain_to_me_what_is_gopath/

https://www.yasint.dev/gopath-goroot

相关推荐
紧跟先前的步伐16 小时前
Go AI Agent 实战 22|完善 Agent 执行循环:从工具调用到最终回答
人工智能·ai·golang
后台模板学习17 小时前
Go Web开发中任务调度框架的源码解析与高可用实现方案
开发语言·后端·golang
FungLeo17 小时前
成为全栈·Go 后端篇·分类树与标签关系:目录变更为何需要协调
golang·go·gorm·数据库事务·分类树·成为全栈
fly-iot18 小时前
【FDE知识库】(1):AI 编程时代开发语言选型分析,云使用go,企业用java,算法python,底层c
开发语言·人工智能·golang
FungLeo18 小时前
成为全栈·Go 后端篇·文章查询与展示投影:安全分页、排序和软删除
golang·go·gorm·分页查询·成为全栈·sql安全
紧跟先前的步伐1 天前
Go AI Agent 实战 24|工具系统工程化收尾与阶段验收
人工智能·ai·golang·1024程序员节
日日大王学编程1 天前
#Feed 流项目复盘:Redis 时间线缓存与 Outbox 消息可靠性设计
golang·1024程序员节
北冥you鱼1 天前
Go 语言 CRUD 实战:从接口设计到真实业务场景
开发语言·后端·golang
利威尔xu2 天前
Go IM 源码实战(11):token 只是个 HASH,多端互踢的顺序错了就踢错人
后端·微服务·面试·架构·golang
microrain2 天前
SagooIoT 把协议解析和消息通知都放进了独立进程
物联网·golang·插件·sagooiot