feat(userapp): 添加用户管理功能模块 - 新增models包,包含User结构体和Base基础结构体 - 实现NewUser构造函数用于创建用户实例 - 添加utils包,提供邮箱和年龄验证工具函数 - 在main.go中集成用户创建和验证逻辑 - 添加包初始化函数init()处理包加载顺序 - 新增README.md文档说明各包功能 ```
31 lines
570 B
Go
31 lines
570 B
Go
package models
|
|
|
|
// userapp 是工程名称
|
|
// models 是 userapp 下的一个包,包含了用户相关的结构体和函数
|
|
// common 是 models 下的一个包,包含了 Base 结构体
|
|
import (
|
|
"fmt"
|
|
"userapp/models/common"
|
|
)
|
|
|
|
type User struct {
|
|
// 嵌套 common.Base 结构体,包含 ID、CreatedAt 和 UpdatedAt 字段
|
|
common.Base
|
|
|
|
Name string
|
|
Email string
|
|
Age int
|
|
}
|
|
|
|
func NewUser(name, email string, age int) *User {
|
|
return &User{
|
|
Name: name,
|
|
Email: email,
|
|
Age: age,
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
fmt.Println("models 包的 init 函数被调用")
|
|
}
|