2026-03-08 11:01:59 +08:00

31 lines
937 B
Go
Raw Permalink 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
// curl localhost:8080/users
r.GET("/users", handlers.GetUsers)
// 无限循环, 知道http server停止或者退出
r.Run() // listen and serve on 0.0.0.0:8080
}