go20/day06/userapp/main.go
yumaojun03 a129d8b476 ```
feat(userapp): 添加用户管理应用的基础架构

- 新增DAO层实现数据访问对象模式,包含用户数据存储功能
- 集成Gin Web框架处理HTTP请求
- 实现用户创建和查询的API处理器
- 添加数据验证工具函数
- 配置项目依赖和模块管理
```
2026-03-01 12:05:06 +08:00

30 lines
906 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
// userapp 是工程名称
// models 是 userapp 下的一个包,包含了用户相关的结构体和函数
//如果models 下面还有其他包,那么需要在这里继续导入 userapp/models/user, models/user 才是才是包名称
// 导入顺序 models.init(userapp/models/user.go init函数) --> common.init(userapp/models/common/base.go init函数)
// init 执行顺序 models.init <-- common.init
"userapp/handlers"
// utils 包包含了一些工具函数
// utils.init(userapp/utils/validators.go init函数)
"github.com/gin-gonic/gin"
)
func main() {
fmt.Println("hello user app")
// web server
r := gin.Default()
// 业务处理
// 处理 GET 请求,路径为 /ping处理函数为 handlers.CreateUser
r.GET("/ping", handlers.GetUsers)
// 无限循环, 知道http server停止或者退出
r.Run() // listen and serve on 0.0.0.0:8080
}