feat(auth): 添加完整的用户认证API项目

- 实现用户注册、登录、JWT令牌认证功能
- 集成Gin、GORM、Viper、Zap等框架
- 添加密码加密、数据库操作、中间件等完整功能
- 配置多环境支持、日志轮转、CORS处理
- 创建完整的项目结构和配置文件体系
This commit is contained in:
liumangmang
2025-12-30 18:00:42 +08:00
parent 7f4527d501
commit b010f82221
139 changed files with 2772 additions and 103 deletions

View File

@@ -0,0 +1,16 @@
package main
import (
"fmt"
"sync/atomic"
)
func main() {
var value int64 = 0
success := atomic.CompareAndSwapInt64(&value, 0, 42)
fmt.Println("第一次 CAS 是否成功:", success, "当前值:", value)
success = atomic.CompareAndSwapInt64(&value, 0, 100)
fmt.Println("第二次 CAS 是否成功:", success, "当前值:", value)
}

View File

@@ -0,0 +1,26 @@
package main
import (
"fmt"
"sync"
"sync/atomic"
)
func main() {
var wg sync.WaitGroup
var counter int64 // 注意必须是 int64/uint64 等特定类型
for i := 0; i < 1000; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < 1000; j++ {
atomic.AddInt64(&counter, 1)
}
}()
}
wg.Wait()
fmt.Println("期待的结果:", 1000*1000)
fmt.Println("实际结果:", counter)
}

View File

@@ -0,0 +1,24 @@
package main
import (
"fmt"
"sync/atomic"
"time"
)
func main() {
var stop int32 = 0
go func() {
for atomic.LoadInt32(&stop) == 0 {
// 忙等:什么也不干,不让出 CPU
}
fmt.Println("worker 退出")
}()
time.Sleep(2 * time.Second)
fmt.Println("main: 设置 stop=1")
atomic.StoreInt32(&stop, 1)
time.Sleep(1 * time.Second)
}

View File

@@ -0,0 +1,23 @@
package main
import (
"fmt"
"time"
)
func main() {
stop := make(chan struct{})
go func() {
select {
case <-stop:
fmt.Println("worker 收到停止信号,退出")
}
}()
time.Sleep(2 * time.Second)
fmt.Println("main: 关闭 stop channel")
close(stop)
time.Sleep(1 * time.Second)
}

View File

@@ -0,0 +1,3 @@
module go-atomic-cpu
go 1.22.2