# crush **Repository Path**: crush_p/crush ## Basic Information - **Project Name**: crush - **Description**: 基于go-fiber封装的web api脚手架 包括 1. 自定义多语言 2. validator验证器 3. gorm库 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-06-15 - **Last Updated**: 2024-06-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # crush ### 介绍 基于go-fiber封装的web api脚手架 包括 1. 自定义多语言 2. validator验证器 3. gorm库 ### 使用说明 框架仅初始化了第三方库,对于第三方库的操作请自行查看其文档。 比如:gorm操作数据库,validator自定义约束,cron定时任务 ### 中间件 1. 把分页与站点语言参数写进了中间件 ``` import "fiber/global" // 获取page page := c.Locals("page").(*global.Page) ``` ### 验证器 ``` // 封装不少函数进了helper,根据需求进行修改 import "fiber/helper" type UserRegister struct { Name string `form:"name" json:"name" validate:"required"` Mobile string `form:"mobile" json:"mobile" validate:"required,checkIdCard"` Password string `form:"password" json:"password" validate:"required"` } user := new(UserRegister) // 自带的绑定参数 if err := c.BodyParser(user); err != nil { // 强校验数据类型或body为空 // 暂时想到的是正则错误字符串,以便返回指定错误(前端先强校验一次可避免) // 后续根据需求看是否需要加上 return helper.Fail(c, err.Error(), global.QueryErrorCode) } // 验证器 if err := helper.ValidateStruct(user, c); err != nil { return helper.Fail(c, err.Error()) } ``` ### 导入第三方包过慢解决办法 ``` go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct ```