Files
liumangmang b010f82221 feat(auth): 添加完整的用户认证API项目
- 实现用户注册、登录、JWT令牌认证功能
- 集成Gin、GORM、Viper、Zap等框架
- 添加密码加密、数据库操作、中间件等完整功能
- 配置多环境支持、日志轮转、CORS处理
- 创建完整的项目结构和配置文件体系
2025-12-30 18:00:42 +08:00

36 lines
644 B
Go

package main
import (
"context"
"fmt"
"time"
)
// 模拟一个可被取消的循环任务
func worker(ctx context.Context, name string) {
for {
select {
case <-ctx.Done():
fmt.Println(name, "收到取消信号:", ctx.Err())
return
default:
fmt.Println(name, "还在干活...")
time.Sleep(500 * time.Millisecond)
}
}
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
go worker(ctx, "worker-1")
go worker(ctx, "worker-2")
time.Sleep(2 * time.Second)
fmt.Println("main: 决定取消所有 worker")
cancel() // 发出取消信号
time.Sleep(1 * time.Second)
fmt.Println("main 结束")
}