166 字
1 分钟
项目最佳实践
项目结构最佳实践
project/├── cmd/ # 应用程序入口│ └── api/│ └── main.go├── internal/ # 私有代码│ ├── config/ # 配置│ ├── models/ # 数据模型│ ├── repository/ # 数据访问层│ ├── service/ # 业务逻辑层│ ├── handler/ # HTTP 处理器│ └── middleware/ # 中间件├── pkg/ # 公共库│ ├── logger/│ ├── validator/│ └── utils/├── api/ # API 定义│ └── openapi.yaml├── migrations/ # 数据库迁移├── scripts/ # 脚本├── docs/ # 文档├── .env.example├── Dockerfile├── docker-compose.yml├── Makefile└── go.mod密码加密
import "golang.org/x/crypto/bcrypt"
func HashPassword(password string) (string, error) { bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) return string(bytes), err}
func CheckPassword(password, hash string) bool { err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) return err == nil}分享文章
生成精美分享图或复制链接,与更多人分享本文。
继续阅读
换条路线
从其他文章中稳定抽取
最后更新于 ,距今已过 89 天
部分内容可能已过时