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 函数被调用")
|
||
|
|
}
|