go20/day06/userapp/utils/validators.go
yumaojun03 6dbefb59ff ```
feat(userapp): 添加用户管理功能模块

- 新增models包,包含User结构体和Base基础结构体
- 实现NewUser构造函数用于创建用户实例
- 添加utils包,提供邮箱和年龄验证工具函数
- 在main.go中集成用户创建和验证逻辑
- 添加包初始化函数init()处理包加载顺序
- 新增README.md文档说明各包功能
```
2026-03-01 11:10:28 +08:00

33 lines
750 B
Go

// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
//
// Package utils contains utility functions.
package utils
import (
"fmt"
"strings"
)
// ValidateEmail 验证邮箱格式
func ValidateEmail(email string) bool {
return strings.Contains(email, "@")
}
// ValidateAge 验证年龄范围
func ValidateAge(age int) bool {
return age > 0 && age < 150
}
func init() {
fmt.Println("utils 包的 init 函数被调用")
}