1 Star 0 Fork 0

码农兴哥/go-demo-2025

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main2_1.go 520 Bytes
一键复制 编辑 原始数据 按行查看 历史
码农兴哥 提交于 2026-01-15 17:56 +08:00 . demo06_context
package main
import (
"context"
"fmt"
)
// context.Background() - 根上下文
func backgroundContextExample() {
fmt.Println("=== Background vs TODO ===")
// 正确:当不确定使用哪个Context时,使用Background
var ctx1 context.Context = context.Background()
// 也正确:当明确需要一个占位符时,使用TODO(较少使用)
var ctx2 context.Context = context.TODO()
fmt.Printf("Background: %T\n", ctx1)
fmt.Printf("TODO: %T\n", ctx2)
}
func main() {
backgroundContextExample()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rxbook/go-demo-2025.git
git@gitee.com:rxbook/go-demo-2025.git
rxbook
go-demo-2025
go-demo-2025
master

搜索帮助