1
This commit is contained in:
parent
9a9f3b71ff
commit
737c0eb28f
5
.gitignore
vendored
5
.gitignore
vendored
@ -11,7 +11,10 @@
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
*.log
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
.idea/
|
||||
.git/
|
||||
.DS_Store/
|
||||
|
||||
48
api/controller/adminUser.go
Normal file
48
api/controller/adminUser.go
Normal file
@ -0,0 +1,48 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/api/service"
|
||||
"knowledge/config"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
)
|
||||
|
||||
type AdminUser struct{}
|
||||
|
||||
func (r *AdminUser) Login(c *gin.Context) {
|
||||
adminUserRequest := requests.AdminUserRequest{}
|
||||
req := adminUserRequest.Login
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
if config.C.Env == "prod" {
|
||||
isValid := utils.VerifyCaptcha(req.CaptchaId, req.Captcha)
|
||||
if !isValid {
|
||||
// 验证码错误
|
||||
responses.FailWithMessage("验证码错误", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 登陆
|
||||
adminUserService := service.AdminUserService{}
|
||||
token, err := adminUserService.Login(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(token, c)
|
||||
}
|
||||
9
api/controller/base.go
Normal file
9
api/controller/base.go
Normal file
@ -0,0 +1,9 @@
|
||||
package controller
|
||||
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Migrate
|
||||
Public // 公共方法-不验证权限
|
||||
AdminUser // 后台用户
|
||||
Question // 题目
|
||||
}
|
||||
165
api/controller/migrate.go
Normal file
165
api/controller/migrate.go
Normal file
@ -0,0 +1,165 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/dao"
|
||||
"knowledge/api/model"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/global"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Migrate struct{}
|
||||
|
||||
var (
|
||||
concurrency = 50 // 最大并发协程的数量
|
||||
running int32 // 当前运行的协程数量
|
||||
wg sync.WaitGroup
|
||||
limiter = make(chan struct{}, concurrency) // 通道作为限流器
|
||||
)
|
||||
|
||||
// Migrate 迁移数据
|
||||
func (r *Migrate) Migrate(c *gin.Context) {
|
||||
// 获取全部数据
|
||||
Testpaper12Dao := dao.Testpaper12Dao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
//maps["id"] = 51134
|
||||
maps["is_migrate"] = 0
|
||||
Testpaper12s, err := Testpaper12Dao.GetTestpaper12List(maps)
|
||||
if err != nil {
|
||||
panic("数据迁移失败! " + err.Error())
|
||||
}
|
||||
|
||||
if len(Testpaper12s) <= 0 {
|
||||
fmt.Println("已全部处理结束")
|
||||
}
|
||||
|
||||
for i, v := range Testpaper12s {
|
||||
wg.Add(1)
|
||||
go doWork(i, v)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
func doWork(i int, v *model.Testpaper12) {
|
||||
defer wg.Done() // goroutine结束就登记-1
|
||||
|
||||
limiter <- struct{}{} // 获取一个令牌
|
||||
atomic.AddInt32(&running, 1)
|
||||
time.Sleep(100 * time.Millisecond) // 模拟工作
|
||||
<-limiter // 释放一个令牌
|
||||
atomic.AddInt32(&running, -1)
|
||||
|
||||
questionDao := dao.QuestionDao{}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
|
||||
// 处理题目名称
|
||||
if v.Name == "" {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
// 题目名称去除前面标点符号
|
||||
re := regexp.MustCompile(`^\d+\.`)
|
||||
questionName := re.ReplaceAllString(v.Name, "")
|
||||
|
||||
re = regexp.MustCompile(`^\d+、`)
|
||||
questionName = re.ReplaceAllString(questionName, "")
|
||||
|
||||
re = regexp.MustCompile(`^\(\d+分\)\d+\.`)
|
||||
questionName = re.ReplaceAllString(questionName, "")
|
||||
|
||||
// 处理答案 【答案】D
|
||||
if v.Answer == "" {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
re = regexp.MustCompile(`[A-Z]+$`)
|
||||
questionAnswer := re.FindString(v.Answer)
|
||||
if questionAnswer == "" {
|
||||
// 未匹配到
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
if questionAnswer == "" {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
// 处理解析
|
||||
questionAnalysis := ""
|
||||
if v.Explain != "" {
|
||||
questionAnalysis = strings.Replace(v.Explain, "【解析】", "", 1)
|
||||
|
||||
questionAnalysis = strings.Replace(questionAnalysis, "【答案解析】", "", 1)
|
||||
}
|
||||
|
||||
// 添加题库表
|
||||
question := &model.Question{
|
||||
QuestionName: questionName,
|
||||
QuestionType: 1, // 题目类型
|
||||
QuestionSource: 1, // 题目来源(1:本题库 2:外部数据)
|
||||
QuestionAnswer: questionAnswer,
|
||||
QuestionAnalysis: questionAnalysis,
|
||||
FirstLabelId: nil,
|
||||
SecondLabelId: nil,
|
||||
}
|
||||
|
||||
question, err := questionDao.AddQuestion(tx, question)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
// 处理选项
|
||||
questionOptions := strings.Split(v.Item, "★")
|
||||
if len(questionOptions) > 0 {
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
|
||||
s := false
|
||||
for _, option := range questionOptions {
|
||||
questionOption := &model.QuestionOption{
|
||||
QuestionId: question.QuestionId,
|
||||
OptionValue: option,
|
||||
}
|
||||
|
||||
questionOption, err := questionOptionDao.AddQuestionOption(tx, questionOption)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
s = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if s {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 修改为已迁移
|
||||
testpaper12Data := make(map[string]interface{})
|
||||
testpaper12Data["is_migrate"] = 1
|
||||
|
||||
Testpaper12Dao := dao.Testpaper12Dao{}
|
||||
err = Testpaper12Dao.EditTestpaper12ById(tx, int64(v.Id), testpaper12Data)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
}
|
||||
22
api/controller/public.go
Normal file
22
api/controller/public.go
Normal file
@ -0,0 +1,22 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/utils"
|
||||
)
|
||||
|
||||
type Public struct{}
|
||||
|
||||
// GetCaptcha 获取验证码
|
||||
func (b *Public) GetCaptcha(c *gin.Context) {
|
||||
id, b64s, err := utils.GenerateCaptcha()
|
||||
if err != nil {
|
||||
responses.FailWithMessage("验证码获取失败", c)
|
||||
}
|
||||
|
||||
responses.OkWithData(gin.H{
|
||||
"id": id,
|
||||
"b64s": b64s,
|
||||
}, c)
|
||||
}
|
||||
85
api/controller/question.go
Normal file
85
api/controller/question.go
Normal file
@ -0,0 +1,85 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/dao"
|
||||
"knowledge/api/dto"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/api/service"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
)
|
||||
|
||||
type Question struct{}
|
||||
|
||||
// GetQuestionPage 获取题目列表-分页
|
||||
func (r *Question) GetQuestionPage(c *gin.Context) {
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
req := questionRequest.GetQuestionPage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
questionDao := dao.QuestionDao{}
|
||||
question, total, err := questionDao.GetQuestionPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetQuestionPageResponses := dto.GetQuestionListDto(question)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetQuestionPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// AddQuestion 新增题目
|
||||
func (r *Question) AddQuestion(c *gin.Context) {
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
req := questionRequest.AddQuestion
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionService := service.QuestionService{}
|
||||
_, err := questionService.AddQuestion(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
90
api/dao/AdminUser.go
Normal file
90
api/dao/AdminUser.go
Normal file
@ -0,0 +1,90 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/api/model"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
type AdminUserDao struct {
|
||||
}
|
||||
|
||||
// GetAdminUserFirstById 获取用户数据-用户id
|
||||
// roleId 用户id
|
||||
func (r *AdminUserDao) GetAdminUserFirstById(userId int64) (m *model.AdminUser, err error) {
|
||||
err = global.Db.First(&m, userId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetAdminUserFirstByAccess 获取用户数据-用户账号
|
||||
func (r *AdminUserDao) GetAdminUserFirstByAccess(access string) (m *model.AdminUser, err error) {
|
||||
err = global.Db.Where("access = ?", access).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetAdminUserFirstByPhone 获取用户数据-手机号
|
||||
func (r *AdminUserDao) GetAdminUserFirstByPhone(phone string) (m *model.AdminUser, err error) {
|
||||
err = global.Db.Where("phone = ?", phone).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteAdminUser 删除用户
|
||||
func (r *AdminUserDao) DeleteAdminUser(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.AdminUser{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteAdminUserById 删除用户-用户id
|
||||
func (r *AdminUserDao) DeleteAdminUserById(tx *gorm.DB, userId int64) error {
|
||||
if err := tx.Delete(&model.AdminUser{}, userId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditAdminUser 修改用户
|
||||
func (r *AdminUserDao) EditAdminUser(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.AdminUser{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditAdminUserById 修改角色-用户id
|
||||
func (r *AdminUserDao) EditAdminUserById(tx *gorm.DB, userId int64, data interface{}) error {
|
||||
err := tx.Model(&model.AdminUser{}).Where("user_id = ?", userId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAdminUserList 获取用户列表
|
||||
func (r *AdminUserDao) GetAdminUserList(maps interface{}) (m []*model.AdminUser, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddAdminUser 新增用户
|
||||
func (r *AdminUserDao) AddAdminUser(tx *gorm.DB, model *model.AdminUser) (*model.AdminUser, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
81
api/dao/Label.go
Normal file
81
api/dao/Label.go
Normal file
@ -0,0 +1,81 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/api/model"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
type LabelDao struct {
|
||||
}
|
||||
|
||||
// GetLabelFirstById 获取数据-id
|
||||
// roleId 用户id
|
||||
func (r *LabelDao) GetLabelFirstById(LabelId int64) (m *model.Label, err error) {
|
||||
err = global.Db.First(&m, LabelId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteLabel 删除
|
||||
func (r *LabelDao) DeleteLabel(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.Label{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteLabelById 删除-id
|
||||
func (r *LabelDao) DeleteLabelById(tx *gorm.DB, LabelId int64) error {
|
||||
if err := tx.Delete(&model.Label{}, LabelId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditLabel 修改
|
||||
func (r *LabelDao) EditLabel(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.Label{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditLabelById 修改-id
|
||||
func (r *LabelDao) EditLabelById(tx *gorm.DB, LabelId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Label{}).Where("label_id = ?", LabelId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLabelList 获取列表
|
||||
func (r *LabelDao) GetLabelList(maps interface{}) (m []*model.Label, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddLabel 新增
|
||||
func (r *LabelDao) AddLabel(tx *gorm.DB, model *model.Label) (*model.Label, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetLabel 获取
|
||||
func (r *LabelDao) GetLabel(maps interface{}) (m *model.Label, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
185
api/dao/Question.go
Normal file
185
api/dao/Question.go
Normal file
@ -0,0 +1,185 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/api/model"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type QuestionDao struct {
|
||||
}
|
||||
|
||||
// GetQuestionFirstById 获取数据-id
|
||||
// roleId 用户id
|
||||
func (r *QuestionDao) GetQuestionFirstById(questionId int64) (m *model.Question, err error) {
|
||||
err = global.Db.First(&m, questionId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteQuestion 删除
|
||||
func (r *QuestionDao) DeleteQuestion(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.Question{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteQuestionById 删除-id
|
||||
func (r *QuestionDao) DeleteQuestionById(tx *gorm.DB, questionId int64) error {
|
||||
if err := tx.Delete(&model.Question{}, questionId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditQuestion 修改
|
||||
func (r *QuestionDao) EditQuestion(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.Question{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditQuestionById 修改-id
|
||||
func (r *QuestionDao) EditQuestionById(tx *gorm.DB, questionId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Question{}).Where("question_id = ?", questionId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetQuestionList 获取列表
|
||||
func (r *QuestionDao) GetQuestionList(maps interface{}) (m []*model.Question, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddQuestion 新增
|
||||
func (r *QuestionDao) AddQuestion(tx *gorm.DB, model *model.Question) (*model.Question, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetQuestion 获取
|
||||
func (r *QuestionDao) GetQuestion(maps interface{}) (m *model.Question, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionPageSearch 获取题目列表-分页
|
||||
func (r *QuestionDao) GetQuestionPageSearch(req requests.GetQuestionPage, page, pageSize int) (m []*model.Question, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.Question{})
|
||||
|
||||
// 一级标签
|
||||
query = query.Preload("FirstLabel", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("label_id", "label_name")
|
||||
})
|
||||
|
||||
// 二级标签
|
||||
query = query.Preload("SecondLabel", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("label_id", "label_name")
|
||||
})
|
||||
|
||||
// 主键id
|
||||
if req.QuestionId != "" {
|
||||
query = query.Where("question_id = ?", req.QuestionId)
|
||||
}
|
||||
|
||||
// 题目名称
|
||||
if req.QuestionName != "" {
|
||||
query = query.Where("question_name LIKE ?", "%"+req.QuestionName+"%")
|
||||
}
|
||||
|
||||
// 题目类型
|
||||
query = query.Where("question_type = ?", req.QuestionType)
|
||||
|
||||
// 状态
|
||||
if req.QuestionStatus != nil {
|
||||
query = query.Where("question_status = ?", req.QuestionStatus)
|
||||
}
|
||||
|
||||
// 难度
|
||||
if req.Difficulty != nil {
|
||||
query = query.Where("difficulty = ?", req.Difficulty)
|
||||
}
|
||||
|
||||
// 题目来源
|
||||
query = query.Where("question_source = ?", req.QuestionSource)
|
||||
|
||||
// 一级标签id
|
||||
if req.FirstLabelId != nil {
|
||||
query = query.Where("first_label_id = ?", req.FirstLabelId)
|
||||
}
|
||||
|
||||
// 二级标签id
|
||||
if req.SecondLabelId != nil {
|
||||
query = query.Where("second_label_id = ?", req.SecondLabelId)
|
||||
}
|
||||
|
||||
// 创建时间
|
||||
if req.CreatedAt != "" {
|
||||
createdAt := strings.Split(req.CreatedAt, "&")
|
||||
if len(createdAt) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", createdAt[0])
|
||||
endTime, _ := time.Parse("2006-01-02", createdAt[1])
|
||||
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 修改时间
|
||||
if req.UpdatedAt != "" {
|
||||
updatedAt := strings.Split(req.UpdatedAt, "&")
|
||||
if len(updatedAt) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", updatedAt[0])
|
||||
endTime, _ := time.Parse("2006-01-02", updatedAt[1])
|
||||
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
query = query.Where("updated_at BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
if req.Order != nil {
|
||||
if req.Order.UpdatedAt != "" {
|
||||
query = query.Order("updated_at " + req.Order.UpdatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
72
api/dao/QuestionOption.go
Normal file
72
api/dao/QuestionOption.go
Normal file
@ -0,0 +1,72 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/api/model"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
type QuestionOptionDao struct {
|
||||
}
|
||||
|
||||
// GetQuestionOptionFirstById 获取数据-id
|
||||
// roleId 用户id
|
||||
func (r *QuestionOptionDao) GetQuestionOptionFirstById(OptionId int64) (m *model.QuestionOption, err error) {
|
||||
err = global.Db.First(&m, OptionId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteQuestionOption 删除
|
||||
func (r *QuestionOptionDao) DeleteQuestionOption(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.QuestionOption{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteQuestionOptionById 删除-id
|
||||
func (r *QuestionOptionDao) DeleteQuestionOptionById(tx *gorm.DB, OptionId int64) error {
|
||||
if err := tx.Delete(&model.QuestionOption{}, OptionId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditQuestionOption 修改
|
||||
func (r *QuestionOptionDao) EditQuestionOption(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.QuestionOption{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditQuestionOptionById 修改-id
|
||||
func (r *QuestionOptionDao) EditQuestionOptionById(tx *gorm.DB, OptionId int64, data interface{}) error {
|
||||
err := tx.Model(&model.QuestionOption{}).Where("option_id = ?", OptionId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetQuestionOptionList 获取列表
|
||||
func (r *QuestionOptionDao) GetQuestionOptionList(maps interface{}) (m []*model.QuestionOption, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddQuestionOption 新增
|
||||
func (r *QuestionOptionDao) AddQuestionOption(tx *gorm.DB, model *model.QuestionOption) (*model.QuestionOption, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
38
api/dao/Testpaper12.go
Normal file
38
api/dao/Testpaper12.go
Normal file
@ -0,0 +1,38 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/api/model"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
type Testpaper12Dao struct {
|
||||
}
|
||||
|
||||
// GetTestpaper12FirstById 获取数据-id
|
||||
// roleId 用户id
|
||||
func (r *Testpaper12Dao) GetTestpaper12FirstById(Id int64) (m *model.Testpaper12, err error) {
|
||||
err = global.Db.First(&m, Id).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetTestpaper12List 获取列表
|
||||
func (r *Testpaper12Dao) GetTestpaper12List(maps interface{}) (m []*model.Testpaper12, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// EditTestpaper12ById 修改-id
|
||||
func (r *Testpaper12Dao) EditTestpaper12ById(tx *gorm.DB, id int64, data interface{}) error {
|
||||
err := tx.Model(&model.Testpaper12{}).Where("id = ?", id).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
48
api/dto/AdminUser.go
Normal file
48
api/dto/AdminUser.go
Normal file
@ -0,0 +1,48 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"knowledge/api/model"
|
||||
"knowledge/utils"
|
||||
)
|
||||
|
||||
// AdminUserDto 后台-用户表
|
||||
type AdminUserDto struct {
|
||||
UserId string `json:"user_id"` // 主键id
|
||||
Access string `json:"access"` // 账号
|
||||
Password string `json:"password"` // 密码
|
||||
Salt string `json:"salt"` // 密码掩码
|
||||
NickName string `json:"nick_name"` // 昵称
|
||||
Status int `json:"status"` // 状态(1:正常 2:审核中 3:审核失败)
|
||||
IsDeleted int `json:"is_deleted"` // 是否被删除(0:否 1:是)
|
||||
IsDisabled int `json:"is_disabled"` // 是否被禁用(0:否 1:是)
|
||||
Phone string `json:"phone"` // 手机号
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Sex int `json:"sex"` // 性别(1:男 2:女)
|
||||
Email string `json:"email"` // 邮箱
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
Token string `json:"token"` // token
|
||||
}
|
||||
|
||||
func LoginDto(m *model.AdminUser) *AdminUserDto {
|
||||
return &AdminUserDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
Access: m.Access,
|
||||
Status: m.Status,
|
||||
NickName: m.NickName,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
Sex: m.Sex,
|
||||
Email: m.Email,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadUserDoctor 加载token
|
||||
func (r *AdminUserDto) LoadUserDoctor(t string) *AdminUserDto {
|
||||
if t != "" {
|
||||
r.Token = t
|
||||
}
|
||||
return r
|
||||
}
|
||||
52
api/dto/Label.go
Normal file
52
api/dto/Label.go
Normal file
@ -0,0 +1,52 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"knowledge/api/model"
|
||||
)
|
||||
|
||||
// LabelDto 标签表
|
||||
type LabelDto struct {
|
||||
LabelId string `json:"label_id"` // 主键id
|
||||
LabelName string `json:"label_name"` // 标签名称
|
||||
ParentId string `json:"parent_id"` // 父级ID(0表示一级)
|
||||
LabelLevel int `json:"label_level"` // 级别(1:1级 2:2级 3:3级)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// GetLabelDto 标签详情
|
||||
func GetLabelDto(m *model.Label) *LabelDto {
|
||||
return &LabelDto{
|
||||
LabelId: fmt.Sprintf("%d", m.LabelId),
|
||||
LabelName: m.LabelName,
|
||||
ParentId: fmt.Sprintf("%d", m.ParentId),
|
||||
LabelLevel: m.LabelLevel,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetLabelListDto 标签列表
|
||||
func GetLabelListDto(m []*model.Label) []*LabelDto {
|
||||
// 处理返回值
|
||||
responses := make([]*LabelDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &LabelDto{
|
||||
LabelId: fmt.Sprintf("%d", v.LabelId),
|
||||
LabelName: v.LabelName,
|
||||
ParentId: fmt.Sprintf("%d", v.ParentId),
|
||||
LabelLevel: v.LabelLevel,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
103
api/dto/Question.go
Normal file
103
api/dto/Question.go
Normal file
@ -0,0 +1,103 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"knowledge/api/model"
|
||||
)
|
||||
|
||||
// QuestionDto 题目表(单选-多选-问答-判断)
|
||||
type QuestionDto struct {
|
||||
QuestionId string `json:"question_id"` // 主键id
|
||||
QuestionName string `json:"question_name"` // 题目名称
|
||||
QuestionType int `json:"question_type"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
|
||||
QuestionStatus int `json:"question_status"` // 状态(1:正常 2:禁用)
|
||||
IsDelete int `json:"is_delete"` // 是否删除(0:否 1:是)
|
||||
QuestionSource int `json:"question_source"` // 题目来源(1:本题库 2:外部数据)
|
||||
QuestionImage []string `json:"question_image"` // 题目图片(逗号分隔)
|
||||
QuestionAnswer string `json:"question_answer"` // 答案
|
||||
QuestionAnalysis string `json:"question_analysis"` // 解析
|
||||
Difficulty int `json:"difficulty"` // 难度(0:未知 1:低 2:中 3:高)
|
||||
FirstLabelId string `json:"first_label_id"` // 一级标签id
|
||||
SecondLabelId string `json:"second_label_id"` // 二级标签id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
FirstLabel *LabelDto `json:"first_label"` // 一级标签
|
||||
SecondLabel *LabelDto `json:"second_label"` // 二级标签
|
||||
}
|
||||
|
||||
// GetQuestionDto 题目详情
|
||||
func GetQuestionDto(m *model.Question) *QuestionDto {
|
||||
return &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", m.QuestionId),
|
||||
QuestionName: m.QuestionName,
|
||||
QuestionType: m.QuestionType,
|
||||
QuestionStatus: m.QuestionStatus,
|
||||
IsDelete: m.IsDelete,
|
||||
QuestionSource: m.QuestionSource,
|
||||
QuestionAnswer: m.QuestionAnswer,
|
||||
QuestionAnalysis: m.QuestionAnalysis,
|
||||
Difficulty: m.Difficulty,
|
||||
FirstLabelId: fmt.Sprintf("%d", *m.FirstLabelId),
|
||||
SecondLabelId: fmt.Sprintf("%d", *m.SecondLabelId),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetQuestionListDto 题目列表
|
||||
func GetQuestionListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionName: v.QuestionName,
|
||||
QuestionType: v.QuestionType,
|
||||
QuestionStatus: v.QuestionStatus,
|
||||
IsDelete: v.IsDelete,
|
||||
QuestionSource: v.QuestionSource,
|
||||
QuestionAnswer: v.QuestionAnswer,
|
||||
QuestionAnalysis: v.QuestionAnalysis,
|
||||
Difficulty: v.Difficulty,
|
||||
FirstLabelId: fmt.Sprintf("%d", *v.FirstLabelId),
|
||||
SecondLabelId: fmt.Sprintf("%d", *v.SecondLabelId),
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载一级标签
|
||||
if v.FirstLabel != nil {
|
||||
response = response.LoadFirstLabel(v.FirstLabel)
|
||||
}
|
||||
|
||||
fmt.Println(v.SecondLabel)
|
||||
// 加载二级标签
|
||||
if v.SecondLabel != nil {
|
||||
response = response.LoadSecondLabel(v.SecondLabel)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadFirstLabel 加载一级标签
|
||||
func (r *QuestionDto) LoadFirstLabel(m *model.Label) *QuestionDto {
|
||||
if m != nil {
|
||||
r.FirstLabel = GetLabelDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadSecondLabel 加载二级标签
|
||||
func (r *QuestionDto) LoadSecondLabel(m *model.Label) *QuestionDto {
|
||||
if m != nil {
|
||||
r.SecondLabel = GetLabelDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
43
api/exception/exception.go
Normal file
43
api/exception/exception.go
Normal file
@ -0,0 +1,43 @@
|
||||
package exception
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/consts"
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
// Recover
|
||||
// @Description: 处理全局异常
|
||||
// @return gin.HandlerFunc
|
||||
func Recover() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 打印错误堆栈信息
|
||||
log.Printf("panic: %v\n", r)
|
||||
debug.PrintStack()
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": consts.ServerError,
|
||||
"message": errorToString(r),
|
||||
"data": "",
|
||||
})
|
||||
// 终止后续接口调用,不加的话recover到异常后,还会继续执行接口里后续代码
|
||||
c.Abort()
|
||||
}
|
||||
}()
|
||||
// 加载完 defer recover,继续后续接口调用
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// recover错误,转string
|
||||
func errorToString(r interface{}) string {
|
||||
switch v := r.(type) {
|
||||
case error:
|
||||
return v.Error()
|
||||
default:
|
||||
return r.(string)
|
||||
}
|
||||
}
|
||||
55
api/middlewares/auth.go
Normal file
55
api/middlewares/auth.go
Normal file
@ -0,0 +1,55 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/dao"
|
||||
"knowledge/api/responses"
|
||||
)
|
||||
|
||||
// Auth Auth认证
|
||||
func Auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 获取用户id
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId == 0 {
|
||||
responses.Fail(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
adminUserDao := dao.AdminUserDao{}
|
||||
adminUser, err := adminUserDao.GetAdminUserFirstById(userId)
|
||||
if err != nil || adminUser == nil {
|
||||
responses.FailWithMessage("用户数据错误", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 2 {
|
||||
responses.FailWithMessage("用户审核中", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 3 {
|
||||
responses.FailWithMessage("用户已删除或禁用", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
responses.FailWithMessage("用户已禁用", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDeleted == 1 {
|
||||
responses.FailWithMessage("用户已删除", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
29
api/middlewares/cors.go
Normal file
29
api/middlewares/cors.go
Normal file
@ -0,0 +1,29 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Cors
|
||||
// @Description: 跨域中间件
|
||||
// @return gin.HandlerFunc
|
||||
func Cors() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
origin := c.Request.Header.Get("Origin")
|
||||
if origin != "" {
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
||||
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
|
||||
c.Header("Access-Control-Allow-Credentials", "false")
|
||||
c.Set("content-type", "application/json")
|
||||
}
|
||||
if method == "OPTIONS" {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
72
api/middlewares/jwt.go
Normal file
72
api/middlewares/jwt.go
Normal file
@ -0,0 +1,72 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/consts"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Jwt jwt认证
|
||||
func Jwt() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
authorization := c.Request.Header.Get("Authorization")
|
||||
if authorization == "" || !strings.HasPrefix(authorization, "Bearer ") {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "请求未授权",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 去除Bearer
|
||||
authorization = authorization[7:] // 截取字符
|
||||
|
||||
// 检测是否存在黑名单
|
||||
res, _ := global.Redis.Get(c, "jwt_black_"+authorization).Result()
|
||||
if res != "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误/过期",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 解析jwt
|
||||
t, err := utils.ParseJwt(authorization)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误/过期",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 转换类型
|
||||
userId, err := strconv.ParseInt(t.UserId, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("UserId", userId) // 用户id
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
60
api/middlewares/logrus.go
Normal file
60
api/middlewares/logrus.go
Normal file
@ -0,0 +1,60 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"knowledge/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Logrus 日志中间件
|
||||
func Logrus() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
// 开始时间
|
||||
startTime := time.Now()
|
||||
|
||||
// 处理请求
|
||||
c.Next()
|
||||
|
||||
// 获取 请求 参数
|
||||
params := make(map[string]string)
|
||||
|
||||
paramsRaw, ok := c.Get("params")
|
||||
if ok {
|
||||
requestParams, ok := paramsRaw.(map[string]string)
|
||||
if ok || len(requestParams) > 0 {
|
||||
params = requestParams
|
||||
}
|
||||
}
|
||||
|
||||
// 结束时间
|
||||
endTime := time.Now()
|
||||
|
||||
// 执行时间
|
||||
latencyTime := fmt.Sprintf("%6v", endTime.Sub(startTime))
|
||||
|
||||
// 请求方式
|
||||
reqMethod := c.Request.Method
|
||||
|
||||
// 请求路由
|
||||
reqUri := c.Request.RequestURI
|
||||
|
||||
// 状态码
|
||||
statusCode := c.Writer.Status()
|
||||
|
||||
// 请求IP
|
||||
clientIP := c.ClientIP()
|
||||
|
||||
// 日志格式
|
||||
global.Logger.WithFields(logrus.Fields{
|
||||
"http_status": statusCode,
|
||||
"total_time": latencyTime,
|
||||
"ip": clientIP,
|
||||
"method": reqMethod,
|
||||
"uri": reqUri,
|
||||
"params": params,
|
||||
}).Info("access")
|
||||
}
|
||||
}
|
||||
92
api/middlewares/requestParamsMiddleware.go
Normal file
92
api/middlewares/requestParamsMiddleware.go
Normal file
@ -0,0 +1,92 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"knowledge/consts"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RequestParamsMiddleware 获取请求参数中间件
|
||||
func RequestParamsMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
contentType := c.Request.Header.Get("Content-Type")
|
||||
|
||||
params := make(map[string]string)
|
||||
|
||||
// 判断请求参数类型
|
||||
switch contentType {
|
||||
case "application/json":
|
||||
// 解析 application/json 请求体
|
||||
bodyBytes, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 创建新的请求对象,并设置请求体数据
|
||||
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
|
||||
var jsonParams map[string]interface{}
|
||||
err = json.Unmarshal(bodyBytes, &jsonParams)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "Invalid JSON data",
|
||||
"code": consts.HttpError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
for key, value := range jsonParams {
|
||||
params[key] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
|
||||
// 存储参数到上下文
|
||||
c.Set("params", params)
|
||||
|
||||
case "multipart/form-data", "application/form-data", "application/x-www-form-urlencoded":
|
||||
// 解析 Form 表单参数
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "Invalid form data",
|
||||
"code": consts.HttpError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
for key, values := range c.Request.Form {
|
||||
if len(values) > 0 {
|
||||
params[key] = fmt.Sprintf("%v", values[0])
|
||||
}
|
||||
}
|
||||
|
||||
// 存储参数到上下文
|
||||
c.Set("params", params)
|
||||
|
||||
default:
|
||||
// 解析 URL 参数
|
||||
queryParams := c.Request.URL.Query()
|
||||
|
||||
for key, values := range queryParams {
|
||||
if len(values) > 0 {
|
||||
params[key] = fmt.Sprintf("%v", values[0])
|
||||
}
|
||||
}
|
||||
|
||||
// 存储参数到上下文
|
||||
c.Set("params", params)
|
||||
}
|
||||
|
||||
// 继续处理请求
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
42
api/model/AdminUser.go
Normal file
42
api/model/AdminUser.go
Normal file
@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AdminUser 后台-用户表
|
||||
type AdminUser struct {
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(20);primary_key;comment:主键id" json:"user_id"`
|
||||
Access string `gorm:"column:access;type:varchar(64);comment:账号;NOT NULL" json:"access"`
|
||||
Password string `gorm:"column:password;type:varchar(128);comment:密码;NOT NULL" json:"password"`
|
||||
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码;NOT NULL" json:"salt"`
|
||||
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态(1:正常 2:审核中 3:审核失败)" json:"status"`
|
||||
IsDeleted int `gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否被删除(0:否 1:是)" json:"is_deleted"`
|
||||
IsDisabled int `gorm:"column:is_disabled;type:tinyint(1);default:0;comment:是否被禁用(0:否 1:是)" json:"is_disabled"`
|
||||
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||||
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别(1:男 2:女)" json:"sex"`
|
||||
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *AdminUser) TableName() string {
|
||||
return "kb_admin_user"
|
||||
}
|
||||
|
||||
func (m *AdminUser) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.UserId == 0 {
|
||||
m.UserId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
34
api/model/Label.go
Normal file
34
api/model/Label.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Label 标签表
|
||||
type Label struct {
|
||||
LabelId int64 `gorm:"column:label_id;type:bigint(19);primary_key;comment:主键id" json:"label_id"`
|
||||
LabelName string `gorm:"column:label_name;type:varchar(255);comment:标签名称" json:"label_name"`
|
||||
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:父级ID(0表示一级)" json:"parent_id"`
|
||||
LabelLevel int `gorm:"column:label_level;type:tinyint(1);default:1;comment:级别(1:1级 2:2级 3:3级)" json:"label_level"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *Label) TableName() string {
|
||||
return "kb_label"
|
||||
}
|
||||
|
||||
func (m *Label) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.LabelId == 0 {
|
||||
m.LabelId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
44
api/model/Question.go
Normal file
44
api/model/Question.go
Normal file
@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Question 题目表(单选-多选-问答-判断)
|
||||
type Question struct {
|
||||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
|
||||
QuestionName string `gorm:"column:question_name;type:varchar(1000);comment:题目名称;NOT NULL" json:"question_name"`
|
||||
QuestionType int `gorm:"column:question_type;type:tinyint(1);default:1;comment:题目类型(1:单选 2:多选 3:问答 4:判断);NOT NULL" json:"question_type"`
|
||||
QuestionStatus int `gorm:"column:question_status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"question_status"`
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:是否删除(0:否 1:是)" json:"is_delete"`
|
||||
QuestionSource int `gorm:"column:question_source;type:tinyint(1);comment:题目来源(1:本题库 2:外部数据);NOT NULL" json:"question_source"`
|
||||
QuestionImage string `gorm:"column:question_image;type:varchar(500);comment:题目图片(逗号分隔)" json:"question_image"`
|
||||
QuestionAnswer string `gorm:"column:question_answer;type:varchar(255);comment:答案" json:"question_answer"`
|
||||
QuestionAnalysis string `gorm:"column:question_analysis;type:text;comment:解析" json:"question_analysis"`
|
||||
Difficulty int `gorm:"column:difficulty;type:tinyint(1);default:0;comment:难度(0:未知 1:低 2:中 3:高)" json:"difficulty"`
|
||||
FirstLabelId *int64 `gorm:"column:first_label_id;type:bigint(19);comment:一级标签id" json:"first_label_id"`
|
||||
SecondLabelId *int64 `gorm:"column:second_label_id;type:bigint(19);comment:二级标签id" json:"second_label_id"`
|
||||
Model
|
||||
FirstLabel *Label `gorm:"foreignKey:FirstLabelId;references:label_id" json:"first_label"`
|
||||
SecondLabel *Label `gorm:"foreignKey:SecondLabelId;references:label_id" json:"second_label"`
|
||||
}
|
||||
|
||||
func (m *Question) TableName() string {
|
||||
return "kb_question"
|
||||
}
|
||||
|
||||
func (m *Question) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.QuestionId == 0 {
|
||||
m.QuestionId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
33
api/model/QuestionOption.go
Normal file
33
api/model/QuestionOption.go
Normal file
@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"knowledge/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// QuestionOption 题目选项表
|
||||
type QuestionOption struct {
|
||||
OptionId int64 `gorm:"column:option_id;type:bigint(19);primary_key;comment:主键id" json:"option_id"`
|
||||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id" json:"question_id"`
|
||||
OptionValue string `gorm:"column:option_value;type:varchar(255);comment:选项内容" json:"option_value"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *QuestionOption) TableName() string {
|
||||
return "kb_question_option"
|
||||
}
|
||||
|
||||
func (m *QuestionOption) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.OptionId == 0 {
|
||||
m.OptionId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
29
api/model/Testpaper12.go
Normal file
29
api/model/Testpaper12.go
Normal file
@ -0,0 +1,29 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Testpaper12 struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
StemType string `gorm:"column:stem_type;type:varchar(1000);comment:题干名称" json:"stem_type"`
|
||||
Name string `gorm:"column:name;type:varchar(1000);comment:题目名称" json:"name"`
|
||||
Item string `gorm:"column:item;type:varchar(1000);comment:选项" json:"item"`
|
||||
Answer string `gorm:"column:answer;type:varchar(1000);comment:答案" json:"answer"`
|
||||
Explain string `gorm:"column:explain;type:varchar(2000);comment:解析" json:"explain"`
|
||||
QuestionType uint `gorm:"column:question_type;type:tinyint(4) unsigned;comment:题目类型" json:"question_type"`
|
||||
Level uint `gorm:"column:level;type:tinyint(4) unsigned;comment:难易程度" json:"level"`
|
||||
KnowledgeType uint `gorm:"column:knowledge_type;type:tinyint(4) unsigned;comment:知识题库分类" json:"knowledge_type"`
|
||||
PaperUuid string `gorm:"column:paper_uuid;type:varchar(50);comment:所属paper;NOT NULL" json:"paper_uuid"`
|
||||
CreateDate time.Time `gorm:"column:create_date;type:datetime" json:"create_date"`
|
||||
IsMigrate uint `gorm:"column:is_migrate;type:tinyint(4) unsigned;comment:是否迁移" json:"is_migrate"`
|
||||
}
|
||||
|
||||
func (m *Testpaper12) TableName() string {
|
||||
return "tb_testpaper12"
|
||||
}
|
||||
|
||||
func (m *Testpaper12) BeforeCreate(tx *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
87
api/model/model.go
Normal file
87
api/model/model.go
Normal file
@ -0,0 +1,87 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
CreatedAt LocalTime `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt LocalTime `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// LocalTime 自定义数据类型
|
||||
type LocalTime time.Time
|
||||
|
||||
func (t *LocalTime) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
// 前端接收的时间字符串
|
||||
str := string(data)
|
||||
// 去除接收的str收尾多余的"
|
||||
timeStr := strings.Trim(str, "\"")
|
||||
t1, err := time.Parse("2006-01-02 15:04:05", timeStr)
|
||||
*t = LocalTime(t1)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t LocalTime) MarshalJSON() ([]byte, error) {
|
||||
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format("2006-01-02 15:04:05"))
|
||||
return []byte(formatted), nil
|
||||
}
|
||||
|
||||
func (t LocalTime) Value() (driver.Value, error) {
|
||||
// MyTime 转换成 time.Time 类型
|
||||
tTime := time.Time(t)
|
||||
return tTime.Format("2006-01-02 15:04:05"), nil
|
||||
}
|
||||
|
||||
func (t *LocalTime) Scan(v interface{}) error {
|
||||
switch vt := v.(type) {
|
||||
case time.Time:
|
||||
// 字符串转成 time.Time 类型
|
||||
*t = LocalTime(vt)
|
||||
default:
|
||||
return errors.New("类型处理错误")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *LocalTime) String() string {
|
||||
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
|
||||
}
|
||||
|
||||
func (t *LocalTime) IsEmpty() bool {
|
||||
return time.Time(*t).IsZero()
|
||||
}
|
||||
|
||||
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
switch {
|
||||
case pageSize > 100:
|
||||
pageSize = 100
|
||||
case pageSize <= 0:
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
return db.Offset(offset).Limit(pageSize)
|
||||
}
|
||||
}
|
||||
13
api/requests/AdminUser.go
Normal file
13
api/requests/AdminUser.go
Normal file
@ -0,0 +1,13 @@
|
||||
package requests
|
||||
|
||||
type AdminUserRequest struct {
|
||||
Login // 登陆
|
||||
}
|
||||
|
||||
// Login 登陆
|
||||
type Login struct {
|
||||
Access string `json:"access" form:"access" validate:"required" label:"用户名"` // 用户名
|
||||
Password string `json:"password" form:"password" validate:"required" label:"密码"` // 密码
|
||||
Captcha string `json:"captcha" form:"captcha" validate:"required" label:"验证码"` // 验证码
|
||||
CaptchaId string `json:"captchaId" form:"captchaId" validate:"required"` // 验证码ID
|
||||
}
|
||||
4
api/requests/base.go
Normal file
4
api/requests/base.go
Normal file
@ -0,0 +1,4 @@
|
||||
package requests
|
||||
|
||||
type Requests struct {
|
||||
}
|
||||
43
api/requests/question.go
Normal file
43
api/requests/question.go
Normal file
@ -0,0 +1,43 @@
|
||||
package requests
|
||||
|
||||
type QuestionRequest struct {
|
||||
GetQuestionPage // 获取题目列表-分页
|
||||
AddQuestion // 新增题目
|
||||
}
|
||||
|
||||
// GetQuestionPage 获取题目列表-分页
|
||||
type GetQuestionPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
QuestionId string `json:"question_id" form:"question_id" label:"主键id"`
|
||||
QuestionName string `json:"question_name" form:"question_name" label:"题目名称"`
|
||||
QuestionType int `json:"question_type" form:"question_type" validate:"required,oneof=1 2 3 4" label:"题目类型"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
|
||||
QuestionStatus *int `json:"question_status" form:"question_status" label:"状态"`
|
||||
QuestionSource int `json:"question_source" form:"question_source" validate:"required,oneof=1 2" label:"题目来源"` // 题目来源(1:本题库 2:外部数据)
|
||||
Difficulty *int `json:"difficulty" form:"difficulty" label:"难度"`
|
||||
FirstLabelId *string `json:"first_label_id" form:"first_label_id" label:"一级标签id"`
|
||||
SecondLabelId *string `json:"second_label_id" form:"second_label_id" label:"二级标签id"`
|
||||
CreatedAt string `json:"created_at" form:"created_at" label:"创建时间"`
|
||||
UpdatedAt string `json:"updated_at" form:"updated_at" label:"修改时间"`
|
||||
Order *GetQuestionPageOrder `json:"order" form:"order" label:"排序"`
|
||||
}
|
||||
|
||||
// GetQuestionPageOrder 获取题目列表-分页-排序条件
|
||||
type GetQuestionPageOrder struct {
|
||||
UpdatedAt string `json:"updated_at" form:"updated_at" label:"排序" validate:"oneof=desc asc"`
|
||||
}
|
||||
|
||||
// AddQuestion 新增题目
|
||||
type AddQuestion struct {
|
||||
QuestionName string `json:"question_name" form:"question_name" validate:"required" label:"题目名称"`
|
||||
QuestionType int `json:"question_type" form:"question_type" validate:"required,oneof=1 2 3 4" label:"题目类型"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
|
||||
QuestionStatus int `json:"question_status" form:"question_status" validate:"required,oneof=1 2" label:"状态"` // 状态(1:正常 2:禁用)
|
||||
QuestionSource int `json:"question_source" form:"question_source" validate:"required,oneof=1 2" label:"题目来源"` // 题目来源(1:本题库 2:外部数据)
|
||||
QuestionAnswer string `json:"question_answer" form:"question_answer" validate:"required" label:"答案"`
|
||||
QuestionAnalysis string `json:"question_analysis" form:"question_analysis" label:"解析"`
|
||||
Difficulty int `json:"difficulty" form:"difficulty" validate:"required,oneof=1 2 3" label:"难度"`
|
||||
FirstLabelId string `json:"first_label_id" form:"first_label_id" validate:"required" label:"一级标签id"`
|
||||
SecondLabelId string `json:"second_label_id" form:"second_label_id" label:"二级标签id"`
|
||||
QuestionImage []string `json:"question_image" form:"question_image" label:"图片"`
|
||||
QuestionOption []string `json:"question_option" form:"question_option" label:"选项"`
|
||||
}
|
||||
52
api/responses/responses.go
Normal file
52
api/responses/responses.go
Normal file
@ -0,0 +1,52 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/consts"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type res struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func result(code int, data interface{}, msg string, c *gin.Context) {
|
||||
if data == nil {
|
||||
data = gin.H{}
|
||||
}
|
||||
c.JSON(http.StatusOK, res{
|
||||
code,
|
||||
data,
|
||||
msg,
|
||||
})
|
||||
}
|
||||
|
||||
func Ok(c *gin.Context) {
|
||||
result(consts.HttpSuccess, map[string]interface{}{}, "成功", c)
|
||||
}
|
||||
|
||||
func OkWithMessage(message string, c *gin.Context) {
|
||||
result(consts.HttpSuccess, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func OkWithData(data interface{}, c *gin.Context) {
|
||||
result(consts.HttpSuccess, data, "成功", c)
|
||||
}
|
||||
|
||||
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
result(consts.HttpSuccess, data, message, c)
|
||||
}
|
||||
|
||||
func Fail(c *gin.Context) {
|
||||
result(consts.HttpError, map[string]interface{}{}, "失败", c)
|
||||
}
|
||||
|
||||
func FailWithMessage(message string, c *gin.Context) {
|
||||
result(consts.HttpError, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
result(consts.HttpError, data, message, c)
|
||||
}
|
||||
113
api/router/router.go
Normal file
113
api/router/router.go
Normal file
@ -0,0 +1,113 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/controller"
|
||||
"knowledge/api/exception"
|
||||
"knowledge/api/middlewares"
|
||||
"knowledge/config"
|
||||
"knowledge/consts"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Init 初始化路由
|
||||
func Init() *gin.Engine {
|
||||
r := gin.New()
|
||||
|
||||
// 环境设置
|
||||
if config.C.Env == "prod" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
// 获取请求参数中间件-json格式下会导致接口获取不到请求数据
|
||||
r.Use(middlewares.RequestParamsMiddleware())
|
||||
|
||||
// 日志中间件
|
||||
r.Use(middlewares.Logrus())
|
||||
|
||||
// 异常
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
// 404处理
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
method := c.Request.Method
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"msg": fmt.Sprintf("%s %s not found", method, path),
|
||||
"code": consts.ClientHttpNotFound,
|
||||
"data": "",
|
||||
})
|
||||
})
|
||||
|
||||
// 异常处理
|
||||
r.Use(exception.Recover())
|
||||
|
||||
// 跨域处理
|
||||
r.Use(middlewares.Cors())
|
||||
|
||||
// 加载基础路由
|
||||
api := controller.Api{}
|
||||
|
||||
// 公开路由-不验证权限
|
||||
publicRouter(r, api)
|
||||
|
||||
// 验证jwt
|
||||
r.Use(middlewares.Jwt())
|
||||
|
||||
// 验证权限
|
||||
r.Use(middlewares.Auth())
|
||||
|
||||
// 私有路由-验证权限
|
||||
privateRouter(r, api)
|
||||
|
||||
// 公共路由-验证权限
|
||||
adminRouter(r, api)
|
||||
|
||||
// 基础数据-验证权限
|
||||
basicRouter(r, api)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// publicRouter 公开路由-不验证权限
|
||||
func publicRouter(r *gin.Engine, api controller.Api) {
|
||||
migrateGroup := r.Group("/migrate")
|
||||
{
|
||||
migrateGroup.GET("", api.Migrate.Migrate)
|
||||
}
|
||||
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 验证码
|
||||
adminGroup.GET("/captcha", api.Public.GetCaptcha)
|
||||
|
||||
// 登陆
|
||||
adminGroup.POST("/login", api.AdminUser.Login)
|
||||
}
|
||||
|
||||
// adminRouter 公共路由-验证权限
|
||||
func adminRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
}
|
||||
|
||||
// basicRouter 基础数据-验证权限
|
||||
func basicRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
}
|
||||
|
||||
// privateRouter 私有路由-验证权限
|
||||
func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 题目
|
||||
questionGroup := adminGroup.Group("/question")
|
||||
{
|
||||
// 获取题目列表-分页
|
||||
questionGroup.POST("/page", api.Question.GetQuestionPage)
|
||||
|
||||
// 新增题目
|
||||
questionGroup.POST("", api.Question.AddQuestion)
|
||||
}
|
||||
|
||||
}
|
||||
66
api/service/AdminUser.go
Normal file
66
api/service/AdminUser.go
Normal file
@ -0,0 +1,66 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"knowledge/api/dao"
|
||||
"knowledge/api/dto"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// AdminUserService 后台用户
|
||||
type AdminUserService struct {
|
||||
}
|
||||
|
||||
func (r *AdminUserService) Login(req requests.Login) (res *dto.AdminUserDto, err error) {
|
||||
// 获取用户信息
|
||||
AdminUserDao := dao.AdminUserDao{}
|
||||
adminUser, err := AdminUserDao.GetAdminUserFirstByAccess(req.Access)
|
||||
if err != nil || adminUser == nil {
|
||||
return nil, errors.New("用户名或密码错误")
|
||||
}
|
||||
|
||||
// 检测用户密码
|
||||
password := md5.Sum([]byte(req.Password + adminUser.Salt))
|
||||
// 将哈希值转换为16进制字符串
|
||||
passwordString := hex.EncodeToString(password[:])
|
||||
|
||||
if passwordString != adminUser.Password {
|
||||
return nil, errors.New("用户名或密码错误")
|
||||
}
|
||||
|
||||
// 检测用户状态
|
||||
if adminUser.IsDeleted == 1 {
|
||||
return nil, errors.New("非法用户")
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
return nil, errors.New("您的账号已被禁用,请联系管理员处理")
|
||||
}
|
||||
|
||||
// 检测用户状态
|
||||
if adminUser.Status != 1 {
|
||||
return nil, errors.New("您的账号已被禁用,请联系管理员处理")
|
||||
}
|
||||
|
||||
token := &utils.Token{
|
||||
UserId: strconv.FormatInt(adminUser.UserId, 10),
|
||||
}
|
||||
|
||||
// 生成jwt
|
||||
jwt, err := token.NewJWT()
|
||||
if err != nil {
|
||||
return nil, errors.New("登陆失败")
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.LoginDto(adminUser)
|
||||
|
||||
// 加载token
|
||||
g.LoadUserDoctor(jwt)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
122
api/service/Question.go
Normal file
122
api/service/Question.go
Normal file
@ -0,0 +1,122 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"knowledge/api/dao"
|
||||
"knowledge/api/model"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type QuestionService struct {
|
||||
}
|
||||
|
||||
// AddQuestion 新增题目
|
||||
func (r *QuestionService) AddQuestion(req requests.AddQuestion) (bool, error) {
|
||||
// 验证一级标签
|
||||
firstLabelId, err := strconv.ParseInt(req.FirstLabelId, 10, 64)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
labelDao := dao.LabelDao{}
|
||||
_, err = labelDao.GetLabelFirstById(firstLabelId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 验证二级标签
|
||||
var secondLabelId int64
|
||||
if req.SecondLabelId != "" {
|
||||
secondLabelId, err := strconv.ParseInt(req.SecondLabelId, 10, 64)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
_, err = labelDao.GetLabelFirstById(secondLabelId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
var questionImage string
|
||||
if len(req.QuestionImage) > 0 {
|
||||
result := make([]string, len(req.QuestionImage))
|
||||
for i, url := range req.QuestionImage {
|
||||
result[i] = utils.RemoveOssDomain(url)
|
||||
}
|
||||
|
||||
questionImage = strings.Join(result, ",")
|
||||
}
|
||||
|
||||
// 判断选项
|
||||
if req.QuestionType == 1 || req.QuestionType == 2 {
|
||||
if len(req.QuestionOption) == 0 {
|
||||
return false, errors.New("请填入选项")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证重复
|
||||
questionDao := dao.QuestionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["question_name"] = req.QuestionName
|
||||
question, _ := questionDao.GetQuestion(maps)
|
||||
if question != nil {
|
||||
return false, errors.New("题目名称重复")
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 新增题目
|
||||
question = &model.Question{
|
||||
QuestionName: req.QuestionName,
|
||||
QuestionType: req.QuestionType,
|
||||
QuestionStatus: req.QuestionStatus,
|
||||
QuestionSource: req.QuestionSource,
|
||||
QuestionImage: questionImage,
|
||||
QuestionAnswer: req.QuestionAnswer,
|
||||
QuestionAnalysis: req.QuestionAnalysis,
|
||||
Difficulty: req.Difficulty,
|
||||
FirstLabelId: &firstLabelId,
|
||||
SecondLabelId: nil,
|
||||
}
|
||||
|
||||
if req.SecondLabelId != "" {
|
||||
question.SecondLabelId = &secondLabelId
|
||||
}
|
||||
|
||||
question, err = questionDao.AddQuestion(tx, question)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
// 新增选项
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
for _, s := range req.QuestionOption {
|
||||
questionOption := &model.QuestionOption{
|
||||
QuestionId: question.QuestionId,
|
||||
OptionValue: s,
|
||||
}
|
||||
|
||||
questionOption, err := questionOptionDao.AddQuestionOption(tx, questionOption)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
}
|
||||
|
||||
//tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
40
config.yaml
Normal file
40
config.yaml
Normal file
@ -0,0 +1,40 @@
|
||||
port: 8398 # 启动端口
|
||||
|
||||
env: dev # 环境配置
|
||||
|
||||
snowflake: 1 # 雪花算法机器id
|
||||
|
||||
# [数据库配置]
|
||||
mysql:
|
||||
host: '42.193.16.243'
|
||||
username: root
|
||||
password: 'gdxz123456^%$d'
|
||||
port: 30001
|
||||
db-name: knowledge_base
|
||||
max-idle-cons: 5
|
||||
max-open-cons: 20
|
||||
debug: true
|
||||
|
||||
log:
|
||||
file-path: "./log/"
|
||||
file-name: "dev-knowledge.log"
|
||||
|
||||
# [redis]
|
||||
redis:
|
||||
host: '139.155.127.177'
|
||||
port: 30002
|
||||
password: gdxz2022&dj.
|
||||
pool-size: 100
|
||||
|
||||
# [jwt]
|
||||
jwt:
|
||||
sign-key: 123456899 # 私钥
|
||||
ttl : 72 # 过期时间 小时
|
||||
algo : HS256 # 加密方式
|
||||
|
||||
oss:
|
||||
oss-access-key: LTAI5tKmFrVCghcxX7yHyGhm
|
||||
oss-access-key-secret: q1aiIZCJJuf92YbKk2cSXnPES4zx26
|
||||
oss-bucket: dev-knowledge
|
||||
oss-endpoint: oss-cn-chengdu.aliyuncs.com
|
||||
oss-custom-domain-name: https://img.applets.igandanyiyuan.com
|
||||
14
config/config.go
Normal file
14
config/config.go
Normal file
@ -0,0 +1,14 @@
|
||||
package config
|
||||
|
||||
var C Config
|
||||
|
||||
type Config struct {
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"`
|
||||
Env string `mapstructure:"env" json:"Env" yaml:"Env"`
|
||||
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
|
||||
Log Log `mapstructure:"log" json:"log" yaml:"log"`
|
||||
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
|
||||
Jwt Jwt `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
|
||||
Oss Oss `mapstructure:"oss" json:"oss" yaml:"oss"`
|
||||
Snowflake int64 `mapstructure:"snowflake" json:"snowflake" yaml:"snowflake"`
|
||||
}
|
||||
7
config/jwt.go
Normal file
7
config/jwt.go
Normal file
@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
type Jwt struct {
|
||||
SignKey string `mapstructure:"sign-key" json:"sign-key" yaml:"sign-key"` // 私钥
|
||||
Ttl int `mapstructure:"ttl" json:"ttl" yaml:"ttl"` // 过期时间 小时
|
||||
Algo string `mapstructure:"algo" json:"algo" yaml:"algo"` // 加密方式
|
||||
}
|
||||
6
config/log.go
Normal file
6
config/log.go
Normal file
@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
type Log struct {
|
||||
FilePath string `mapstructure:"file-path" json:"file-path" yaml:"file-path"` // 日志目录
|
||||
FileName string `mapstructure:"file-name" json:"file-name" yaml:"file-name"` // 日志名称
|
||||
}
|
||||
12
config/mysql.go
Normal file
12
config/mysql.go
Normal file
@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
type Mysql struct {
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
DbName string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-cons" json:"MaxIdleConns" yaml:"max-idle-cons"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-cons" json:"MaxOpenConns" yaml:"max-open-cons"` // 打开到数据库的最大连接数
|
||||
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"` // 是否开启Gorm全局日志
|
||||
}
|
||||
9
config/oss.go
Normal file
9
config/oss.go
Normal file
@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
type Oss struct {
|
||||
OssAccessKey string `mapstructure:"oss-access-key" json:"oss-access-key" yaml:"oss-access-key"`
|
||||
OssAccessKeySecret string `mapstructure:"oss-access-key-secret" json:"oss-access-key-secret" yaml:"oss-access-key-secret"`
|
||||
OssBucket string `mapstructure:"oss-bucket" json:"oss-bucket" yaml:"oss-bucket"`
|
||||
OssEndpoint string `mapstructure:"oss-endpoint" json:"oss-endpoint" yaml:"oss-endpoint"`
|
||||
OssCustomDomainName string `mapstructure:"oss-custom-domain-name" json:"oss-custom-domain-name" yaml:"oss-custom-domain-name"`
|
||||
}
|
||||
8
config/redis.go
Normal file
8
config/redis.go
Normal file
@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
type Redis struct {
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 服务器端口
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
|
||||
PoolSize int `mapstructure:"pool-size" json:"pool-size" yaml:"pool-size"` // 连接池大小
|
||||
}
|
||||
24
consts/http.go
Normal file
24
consts/http.go
Normal file
@ -0,0 +1,24 @@
|
||||
package consts
|
||||
|
||||
// 业务状态码
|
||||
const (
|
||||
HttpSuccess = 200 // 成功
|
||||
|
||||
HttpError = -1 // 失败
|
||||
|
||||
UserStatusError = 201 // 用户状态异常
|
||||
|
||||
ClientHttpError = 400 // 错误请求
|
||||
|
||||
ClientHttpUnauthorized = 401 // 未授权
|
||||
|
||||
HttpProhibit = 403 // 禁止请求
|
||||
|
||||
ClientHttpNotFound = 404 // 资源未找到
|
||||
|
||||
TokenError = 405 // token错误/无效
|
||||
|
||||
TokenExptired = 406 // token过期
|
||||
|
||||
ServerError = 500 // 服务器异常
|
||||
)
|
||||
46
core/logrus.go
Normal file
46
core/logrus.go
Normal file
@ -0,0 +1,46 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"knowledge/config"
|
||||
"knowledge/global"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Logrus 日志记录到文件
|
||||
func Logrus() *logrus.Logger {
|
||||
// 日志文件
|
||||
fileName := path.Join(config.C.Log.FilePath, config.C.Log.FileName)
|
||||
|
||||
// 获取文件夹路径
|
||||
dirPath := filepath.Dir(fileName)
|
||||
|
||||
// 创建文件夹(如果不存在)
|
||||
err := os.MkdirAll(dirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
panic("初始化日志文件失败")
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
src, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm)
|
||||
if err != nil {
|
||||
panic("初始化日志文件失败")
|
||||
}
|
||||
|
||||
global.Logger = logrus.New()
|
||||
|
||||
// 设置输出
|
||||
global.Logger.Out = src
|
||||
|
||||
// 设置日志级别
|
||||
global.Logger.SetLevel(logrus.DebugLevel)
|
||||
|
||||
// 设置日志格式
|
||||
global.Logger.SetFormatter(&logrus.TextFormatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
})
|
||||
|
||||
return global.Logger
|
||||
}
|
||||
56
core/mysql.go
Normal file
56
core/mysql.go
Normal file
@ -0,0 +1,56 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"knowledge/config"
|
||||
"knowledge/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Mysql() {
|
||||
var err error
|
||||
|
||||
m := config.C.Mysql
|
||||
dsn := fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&timeout=%s", m.Username,
|
||||
m.Password, m.Host, m.Port, m.DbName, "10s")
|
||||
|
||||
// newLogger := logger.New(
|
||||
// global.Logger,
|
||||
// logger.Config{
|
||||
// SlowThreshold: time.Second, // Slow SQL threshold
|
||||
// LogLevel: logger.Info, // Log level
|
||||
// IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||||
// ParameterizedQueries: false, // Don't include params in the SQL log
|
||||
// Colorful: false, // Disable color
|
||||
// },
|
||||
// )
|
||||
|
||||
global.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
// Logger: newLogger,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
sqlDB, _ := global.Db.DB()
|
||||
|
||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
|
||||
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
|
||||
|
||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||
sqlDB.SetConnMaxLifetime(time.Hour)
|
||||
|
||||
// 调试模式
|
||||
// Db.LogMode(m.Debug) // 打印sql
|
||||
// Db.SingularTable(true) // 全局禁用表名复数
|
||||
fmt.Println("初始化数据库成功......")
|
||||
}
|
||||
25
core/redis.go
Normal file
25
core/redis.go
Normal file
@ -0,0 +1,25 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"knowledge/config"
|
||||
"knowledge/global"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Redis redis缓存
|
||||
func Redis() {
|
||||
global.Redis = redis.NewClient(&redis.Options{
|
||||
Addr: config.C.Redis.Host + ":" + strconv.Itoa(config.C.Redis.Port),
|
||||
Password: config.C.Redis.Password, // no password set
|
||||
DB: 0, // use default DB
|
||||
PoolSize: config.C.Redis.PoolSize,
|
||||
})
|
||||
_, err := global.Redis.Ping(context.Background()).Result()
|
||||
if err != nil {
|
||||
panic("redis初始化失败! " + err.Error())
|
||||
}
|
||||
fmt.Println("初始化redis成功......")
|
||||
}
|
||||
21
core/snowflake.go
Normal file
21
core/snowflake.go
Normal file
@ -0,0 +1,21 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"knowledge/config"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
// Snowflake 雪花算法
|
||||
func Snowflake() {
|
||||
// 创建雪花算法实例
|
||||
node, err := snowflake.NewNode(config.C.Snowflake)
|
||||
if err != nil {
|
||||
panic("snowflake初始化失败! " + err.Error())
|
||||
}
|
||||
|
||||
global.Snowflake = node
|
||||
|
||||
fmt.Println("初始化snowflake成功......")
|
||||
}
|
||||
95
core/validator.go
Normal file
95
core/validator.go
Normal file
@ -0,0 +1,95 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/go-playground/locales/zh"
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
"github.com/go-playground/validator/v10"
|
||||
zhTranslations "github.com/go-playground/validator/v10/translations/zh"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Validator 验证器
|
||||
func Validator() {
|
||||
chzh := zh.New()
|
||||
uni := ut.New(chzh, chzh)
|
||||
global.Trans, _ = uni.GetTranslator("zh")
|
||||
|
||||
global.Validate = validator.New()
|
||||
|
||||
// 通过label标签返回自定义错误内容
|
||||
global.Validate.RegisterTagNameFunc(func(field reflect.StructField) string {
|
||||
label := field.Tag.Get("label")
|
||||
if label == "" {
|
||||
return field.Name
|
||||
}
|
||||
return label
|
||||
})
|
||||
_ = zhTranslations.RegisterDefaultTranslations(global.Validate, global.Trans)
|
||||
// 注册自定义函数和标签
|
||||
// 手机号验证
|
||||
_ = global.Validate.RegisterValidation("Mobile", mobile) // 注册自定义函数,前一个参数是struct里tag自定义,后一个参数是自定义的函数
|
||||
|
||||
// 自定义required错误内容
|
||||
_ = global.Validate.RegisterTranslation("required", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("required", "{0}为必填字段!", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("required", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义max错误内容
|
||||
_ = global.Validate.RegisterTranslation("max", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("max", "{0}超出最大长度", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("max", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义min错误内容
|
||||
_ = global.Validate.RegisterTranslation("min", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("min", "{0}超出最小长度", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("min", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义lt错误内容
|
||||
_ = global.Validate.RegisterTranslation("lt", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("lt", "{0}超出最大值", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("lt", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义min错误内容
|
||||
_ = global.Validate.RegisterTranslation("gt", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("gt", "{0}不满足最小值", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("gt", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义email错误内容
|
||||
_ = global.Validate.RegisterTranslation("email", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("email", "{0}邮件格式错误", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("email", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义mobile错误内容
|
||||
_ = global.Validate.RegisterTranslation("Mobile", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("mobile", "手机号格式错误", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("mobile", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 自定义手机号验证
|
||||
func mobile(fl validator.FieldLevel) bool {
|
||||
return utils.RegexpMobile(fl.Field().String())
|
||||
}
|
||||
41
core/viper.go
Normal file
41
core/viper.go
Normal file
@ -0,0 +1,41 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
"knowledge/config"
|
||||
)
|
||||
|
||||
// Viper 初始化配置文件
|
||||
func Viper() {
|
||||
// 如需增加环境判断 在此处增加
|
||||
// 可根据 命令行 > 环境变量 > 默认值 等优先级进行判别读取
|
||||
viper.New()
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath("./")
|
||||
viper.SetConfigType("yaml")
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
panic("未找到该文件")
|
||||
} else {
|
||||
panic("读取失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 将读取的配置信息保存至全局变量Conf
|
||||
if err := viper.Unmarshal(&config.C); err != nil {
|
||||
panic(fmt.Errorf("解析配置文件失败, err:%s \n", err))
|
||||
}
|
||||
|
||||
// 自动监听配置修改
|
||||
viper.WatchConfig()
|
||||
|
||||
// 配置文件发生变化后同步到全局变量Conf
|
||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||
fmt.Println("config file changed:", e.Name)
|
||||
if err := viper.Unmarshal(&config.C); err != nil {
|
||||
panic(fmt.Errorf("重载配置文件失败, err:%s \n", err))
|
||||
}
|
||||
})
|
||||
}
|
||||
186
extend/aliyun/oss.go
Normal file
186
extend/aliyun/oss.go
Normal file
@ -0,0 +1,186 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"io"
|
||||
"knowledge/config"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GetOssSignResponse 获取oss签名返回值
|
||||
type GetOssSignResponse struct {
|
||||
AccessId string `json:"access_id"` // 主键id
|
||||
Host string `json:"host"`
|
||||
Policy string `json:"policy"`
|
||||
Signature string `json:"signature"`
|
||||
Expire int64 `json:"expire"`
|
||||
Callback string `json:"callback"`
|
||||
Dir string `json:"dir"`
|
||||
}
|
||||
|
||||
// GetOssSign 获取oss签名
|
||||
func GetOssSign(dir string) (*GetOssSignResponse, error) {
|
||||
now := time.Now()
|
||||
expire := 30 // 设置该policy超时时间是30s,即这个policy过了这个有效时间,将不能访问。
|
||||
end := now.Add(time.Second * time.Duration(expire))
|
||||
expiration := strings.Replace(end.Format("2006-01-02T15:04:05.000Z"), "+00:00", ".000Z", 1)
|
||||
|
||||
start := []interface{}{"starts-with", "$key", dir}
|
||||
conditions := [][]interface{}{start}
|
||||
|
||||
arr := map[string]interface{}{
|
||||
"expiration": expiration,
|
||||
"conditions": conditions,
|
||||
}
|
||||
policy, _ := json.Marshal(arr)
|
||||
base64Policy := base64.StdEncoding.EncodeToString(policy)
|
||||
stringToSign := base64Policy
|
||||
h := hmac.New(sha1.New, []byte(config.C.Oss.OssAccessKeySecret))
|
||||
h.Write([]byte(stringToSign))
|
||||
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||
|
||||
response := &GetOssSignResponse{
|
||||
AccessId: config.C.Oss.OssAccessKey,
|
||||
Host: config.C.Oss.OssCustomDomainName,
|
||||
Policy: base64Policy,
|
||||
Signature: signature,
|
||||
Expire: end.Unix(),
|
||||
Callback: "",
|
||||
Dir: dir,
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// CreateClient 创建客户端
|
||||
func CreateClient() (*oss.Client, error) {
|
||||
// 创建OSSClient实例。
|
||||
client, err := oss.New(config.C.Oss.OssEndpoint, config.C.Oss.OssAccessKey, config.C.Oss.OssAccessKeySecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// GetCusTomObjectToRAM 下载自定义风格文件到内存
|
||||
func GetCusTomObjectToRAM(filename string, style string) (string, error) {
|
||||
if style == "" {
|
||||
style = "image/resize"
|
||||
}
|
||||
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 下载文件到流。
|
||||
body, err := bucket.GetObject(filename, oss.Process(style))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
defer func(body io.ReadCloser) {
|
||||
_ = body.Close()
|
||||
}(body)
|
||||
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetObjectToRAM 下载文件到内存
|
||||
func GetObjectToRAM(filename string) (string, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 下载文件到流。
|
||||
body, err := bucket.GetObject(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
defer func(body io.ReadCloser) {
|
||||
_ = body.Close()
|
||||
}(body)
|
||||
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetObjectToLocal 下载文件到本地
|
||||
func GetObjectToLocal(filename, local string) (bool, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 下载文件到本地文件,并保存到指定的本地路径中。如果指定的本地文件存在会覆盖,不存在则新建。
|
||||
// 如果未指定本地路径,则下载后的文件默认保存到示例程序所属项目对应本地路径中。
|
||||
// 依次填写Object完整路径(例如exampledir/exampleobject.txt)和本地文件的完整路径(例如D:\\localpath\\examplefile.txt)。Object完整路径中不能包含Bucket名称。
|
||||
err = bucket.GetObjectToFile(filename, local)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PutObjectByte 上传文件
|
||||
func PutObjectByte(filename string, content []byte) (bool, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = bucket.PutObject(filename, bytes.NewReader(content))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
20
global/global.go
Normal file
20
global/global.go
Normal file
@ -0,0 +1,20 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/snowflake"
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 全局变量
|
||||
var (
|
||||
Db *gorm.DB // 数据库
|
||||
Logger *logrus.Logger // 日志
|
||||
Redis *redis.Client // redis
|
||||
Validate *validator.Validate // 验证器
|
||||
Trans ut.Translator // Validate/v10 全局验证器
|
||||
Snowflake *snowflake.Node // 雪花算法
|
||||
)
|
||||
101
go.mod
Normal file
101
go.mod
Normal file
@ -0,0 +1,101 @@
|
||||
module knowledge
|
||||
|
||||
go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.7
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v3 v3.0.6
|
||||
github.com/alibabacloud-go/tea v1.2.2
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.5
|
||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
github.com/facebookarchive/grace v0.0.0-20180706040059-75cf19382434
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/gen2brain/go-fitz v1.23.7
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/go-playground/locales v0.14.1
|
||||
github.com/go-playground/universal-translator v0.18.1
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/mojocn/base64Captcha v1.3.6
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/viper v1.19.0
|
||||
github.com/streadway/amqp v1.1.0
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||
github.com/xuri/excelize/v2 v2.8.1
|
||||
gorm.io/driver/mysql v1.5.7
|
||||
gorm.io/gorm v1.25.10
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect
|
||||
github.com/alibabacloud-go/debug v1.0.0 // indirect
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||
github.com/alibabacloud-go/openapi-util v0.1.0 // indirect
|
||||
github.com/alibabacloud-go/tea-utils v1.3.1 // indirect
|
||||
github.com/alibabacloud-go/tea-xml v1.1.3 // indirect
|
||||
github.com/aliyun/credentials-go v1.3.1 // indirect
|
||||
github.com/bytedance/sonic v1.11.6 // indirect
|
||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.5.5 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
|
||||
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
|
||||
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 // indirect
|
||||
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 // indirect
|
||||
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2 // indirect
|
||||
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
|
||||
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
|
||||
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/richardlehane/mscfb v1.0.4 // indirect
|
||||
github.com/richardlehane/msoleps v1.0.3 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/tjfoc/gmsm v1.3.2 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
|
||||
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/image v0.14.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
344
go.sum
Normal file
344
go.sum
Normal file
@ -0,0 +1,344 @@
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 h1:iC9YFYKDGEy3n/FtqJnOkZsene9olVspKmkX5A2YBEo=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.2/go.mod h1:5JHVmnHvGzR2wNdgaW1zDLQG8kOC4Uec8ubkMogW7OQ=
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.7 h1:20vl9plHhHuy9A72oAZSAB4ooov+yY9xfu+cCNcrLh8=
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.7/go.mod h1:CzQnh+94WDnJOnKZH5YRyouL+OOcdBnXY5VWAf0McgI=
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY=
|
||||
github.com/alibabacloud-go/debug v1.0.0 h1:3eIEQWfay1fB24PQIEzXAswlVJtdQok8f3EVN5VrBnA=
|
||||
github.com/alibabacloud-go/debug v1.0.0/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v3 v3.0.6 h1:UTl97mt2qfavxveqCkaVg4tKaZUPzA9RKbFIRaIdtdg=
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v3 v3.0.6/go.mod h1:UWpcGrWwTbES9QW7OQ7xDffukMJ/l7lzioixIz8+lgY=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.11/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/openapi-util v0.1.0 h1:0z75cIULkDrdEhkLWgi9tnLe+KhAFE/r5Pb3312/eAY=
|
||||
github.com/alibabacloud-go/openapi-util v0.1.0/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
|
||||
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea v1.1.19/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea v1.2.1/go.mod h1:qbzof29bM/IFhLMtJPrgTGK3eauV5J2wSyEUo4OEmnA=
|
||||
github.com/alibabacloud-go/tea v1.2.2 h1:aTsR6Rl3ANWPfqeQugPglfurloyBJY85eFy7Gc1+8oU=
|
||||
github.com/alibabacloud-go/tea v1.2.2/go.mod h1:CF3vOzEMAG+bR4WOql8gc2G9H3EkH3ZLAQdpmpXMgwk=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.1 h1:iWQeRzRheqCMuiF3+XkfybB3kTgUXkXX+JMrqfLeB2I=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.0/go.mod h1:U5MTY10WwlquGPS34DOeomUGBB0gXbLueiq5Trwu0C4=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.3/go.mod h1:sj1PbjPodAVTqGTA3olprfeeqqmwD0A5OQz94o9EuXQ=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.5 h1:EUakYEUAwr6L3wLT0vejIw2rc0IA1RSXDwLnIb3f2vU=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.5/go.mod h1:dL6vbUT35E4F4bFTHL845eUloqaerYBYPsdWR2/jhe4=
|
||||
github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
|
||||
github.com/alibabacloud-go/tea-xml v1.1.3 h1:7LYnm+JbOq2B+T/B0fHC4Ies4/FofC4zHzYtqw7dgt0=
|
||||
github.com/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
|
||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
|
||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
||||
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
|
||||
github.com/aliyun/credentials-go v1.3.1 h1:uq/0v7kWrxmoLGpqjx7vtQ/s03f0zR//0br/xWDTE28=
|
||||
github.com/aliyun/credentials-go v1.3.1/go.mod h1:8jKYhQuDawt8x2+fusqa1Y6mPxemTsBEN04dgcAcYz0=
|
||||
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
||||
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
|
||||
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
|
||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E=
|
||||
github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
|
||||
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
|
||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/facebookarchive/grace v0.0.0-20180706040059-75cf19382434 h1:AFIATPhFj7mrISc4z9zEpfm4a8UfwsCWzJ+Je5jA5Rs=
|
||||
github.com/facebookarchive/grace v0.0.0-20180706040059-75cf19382434/go.mod h1:PY9iiFMrFjTzegsqfKCcb+Ekk5/j0ch0sMdBwlT6atI=
|
||||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
|
||||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
|
||||
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
|
||||
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
|
||||
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 h1:wWke/RUCl7VRjQhwPlR/v0glZXNYzBHdNUzf/Am2Nmg=
|
||||
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9/go.mod h1:uPmAp6Sws4L7+Q/OokbWDAK1ibXYhB3PXFP1kol5hPg=
|
||||
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 h1:mOp33BLbcbJ8fvTAmZacbBiOASfxN+MLcLxymZCIrGE=
|
||||
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434/go.mod h1:KigFdumBXUPSwzLDbeuzyt0elrL7+CP7TKuhrhT4bcU=
|
||||
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2 h1:nXeeRHmgNgjLxi+7dY9l9aDvSS1uwVlNLqUWIY4Ath0=
|
||||
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2/go.mod h1:TUV/fX3XrTtBQb5+ttSUJzcFgLNpILONFTKmBuk5RSw=
|
||||
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
|
||||
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
|
||||
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 h1:0YtRCqIZs2+Tz49QuH6cJVw/IFqzo39gEqZ0iYLxD2M=
|
||||
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4/go.mod h1:vsJz7uE339KUCpBXx3JAJzSRH7Uk4iGGyJzR529qDIA=
|
||||
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
|
||||
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/gen2brain/go-fitz v1.23.7 h1:HPhzEVzmOINvCKqQgB/DwMzYh4ArIgy3tMwq1eJTcbg=
|
||||
github.com/gen2brain/go-fitz v1.23.7/go.mod h1:HU04vc+RisUh/kvEd2pB0LAxmK1oyXdN4ftyshUr9rQ=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
|
||||
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||
github.com/mojocn/base64Captcha v1.3.6 h1:gZEKu1nsKpttuIAQgWHO+4Mhhls8cAKyiV2Ew03H+Tw=
|
||||
github.com/mojocn/base64Captcha v1.3.6/go.mod h1:i5CtHvm+oMbj1UzEPXaA8IH/xHFZ3DGY3Wh3dBpZ28E=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
|
||||
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
|
||||
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
|
||||
github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
|
||||
github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
|
||||
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
|
||||
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
|
||||
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
|
||||
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
|
||||
github.com/streadway/amqp v1.1.0 h1:py12iX8XSyI7aN/3dUT8DFIDJazNJsVJdxNVEpnQTZM=
|
||||
github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf88uS9Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
|
||||
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18 h1:vj5tvSmnEIz3ZsnFNNUzg+3Z46xgNMJbrO4aD4wP15w=
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
|
||||
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 h1:Chd9DkqERQQuHpXjR/HSV1jLZA6uaoiwwH3vSuF3IW0=
|
||||
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
|
||||
github.com/xuri/excelize/v2 v2.8.1 h1:pZLMEwK8ep+CLIUWpWmvW8IWE/yxqG0I1xcN6cVMGuQ=
|
||||
github.com/xuri/excelize/v2 v2.8.1/go.mod h1:oli1E4C3Pa5RXg1TBXn4ENCXDV5JUMlBluUhG7c+CEE=
|
||||
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4=
|
||||
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||
golang.org/x/image v0.13.0/go.mod h1:6mmbMOeV28HuMTgA6OSRkdXKYw/t5W9Uwn2Yv1r3Yxk=
|
||||
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
|
||||
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
|
||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
||||
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
|
||||
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
47
main.go
Normal file
47
main.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/facebookarchive/grace/gracehttp"
|
||||
"knowledge/api/router"
|
||||
"knowledge/config"
|
||||
"knowledge/core"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 加载配置文件
|
||||
core.Viper()
|
||||
|
||||
// 加载日志
|
||||
core.Logrus()
|
||||
|
||||
// 加载数据库
|
||||
core.Mysql()
|
||||
|
||||
// 加载redis缓存
|
||||
core.Redis()
|
||||
|
||||
// 加载验证器
|
||||
core.Validator()
|
||||
|
||||
// 加载雪花算法
|
||||
core.Snowflake()
|
||||
|
||||
// 初始化路由-加载中间件
|
||||
r := router.Init()
|
||||
|
||||
// 启动 HTTP 服务器
|
||||
server := &http.Server{
|
||||
Addr: ":" + strconv.Itoa(config.C.Port), // 设置服务器监听的端口号
|
||||
Handler: r,
|
||||
}
|
||||
|
||||
// 使用 grace 运行服务器
|
||||
err := gracehttp.Serve(server)
|
||||
if err != nil {
|
||||
fmt.Printf("启动失败:%v\n\n", err)
|
||||
}
|
||||
}
|
||||
51
utils/captcha.go
Normal file
51
utils/captcha.go
Normal file
@ -0,0 +1,51 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"image/color"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GenerateCaptcha 生成验证码-base64
|
||||
func GenerateCaptcha() (id, b64s string, err error) {
|
||||
var driver *base64Captcha.DriverString
|
||||
// 配置验证码的参数
|
||||
driverString := &base64Captcha.DriverString{
|
||||
Height: 40,
|
||||
Width: 100,
|
||||
NoiseCount: 0,
|
||||
ShowLineOptions: 0,
|
||||
Length: 4,
|
||||
Source: "1234567890",
|
||||
BgColor: &color.RGBA{R: 3, G: 102, B: 214, A: 125},
|
||||
Fonts: []string{"wqy-microhei.ttc"},
|
||||
}
|
||||
// ConvertFonts 按名称加载字体
|
||||
driver = driverString.ConvertFonts()
|
||||
|
||||
base64Captcha.Expiration = 30 * time.Minute
|
||||
store := base64Captcha.DefaultMemStore
|
||||
|
||||
captcha := base64Captcha.NewCaptcha(driver, store)
|
||||
id, b64s, _, err = captcha.Generate()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return id, b64s, nil
|
||||
}
|
||||
|
||||
// VerifyCaptcha 验证验证码
|
||||
func VerifyCaptcha(id, answer string) bool {
|
||||
// 创建验证码实例
|
||||
base64Captcha.Expiration = 30 * time.Minute
|
||||
store := base64Captcha.DefaultMemStore
|
||||
captcha := base64Captcha.NewCaptcha(nil, store)
|
||||
|
||||
// 验证验证码
|
||||
isValid := captcha.Verify(id, answer, true)
|
||||
if !isValid {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
85
utils/compute.go
Normal file
85
utils/compute.go
Normal file
@ -0,0 +1,85 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gen2brain/go-fitz"
|
||||
"image/jpeg"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// 一些计算
|
||||
|
||||
// ComputeIndividualIncomeTax 计算个人所得税
|
||||
func ComputeIndividualIncomeTax(income float64) float64 {
|
||||
if income <= 800 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if income <= 4000 {
|
||||
income = income - 800
|
||||
}
|
||||
|
||||
// 实际纳税金额
|
||||
if income > 4000 {
|
||||
income = income * 0.8
|
||||
}
|
||||
|
||||
// 税率、速算扣除数
|
||||
var taxRate, quickDeduction float64
|
||||
|
||||
if income <= 20000 {
|
||||
taxRate = 0.2
|
||||
quickDeduction = 0
|
||||
} else if income <= 50000 {
|
||||
taxRate = 0.3
|
||||
quickDeduction = 2000
|
||||
} else {
|
||||
taxRate = 0.4
|
||||
quickDeduction = 7000
|
||||
}
|
||||
|
||||
incomeTax := income*taxRate - quickDeduction
|
||||
|
||||
return incomeTax
|
||||
}
|
||||
|
||||
// ConvertPDFToImages converts a PDF file to images and saves them in the specified output directory.
|
||||
func ConvertPDFToImages(pdfPath string, outputDir string, filename string) error {
|
||||
// Open the PDF file
|
||||
doc, err := fitz.New(pdfPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open PDF file: %v", err)
|
||||
}
|
||||
defer doc.Close()
|
||||
|
||||
// Ensure the output directory exists
|
||||
if err := os.MkdirAll(outputDir, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("failed to create output directory: %v", err)
|
||||
}
|
||||
|
||||
// Iterate over each page in the PDF
|
||||
for i := 0; i < doc.NumPage(); i++ {
|
||||
// Render the page to an image
|
||||
img, err := doc.Image(i)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to render page %d: %v", i, err)
|
||||
}
|
||||
|
||||
// Create the output file
|
||||
outputFile := filepath.Join(outputDir, filename)
|
||||
file, err := os.Create(outputFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Encode the image as JPEG and save it to the file
|
||||
opts := &jpeg.Options{Quality: 80}
|
||||
if err := jpeg.Encode(file, img, opts); err != nil {
|
||||
return fmt.Errorf("failed to encode image: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
21
utils/directory.go
Normal file
21
utils/directory.go
Normal file
@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PathExists 文件是否存在
|
||||
func PathExists(path string) (bool, error) {
|
||||
fi, err := os.Stat(path)
|
||||
if err == nil {
|
||||
if fi.IsDir() {
|
||||
return true, nil
|
||||
}
|
||||
return false, errors.New("存在同名文件")
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
298
utils/export.go
Normal file
298
utils/export.go
Normal file
@ -0,0 +1,298 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// func Export(widths []int) (bool, error) {
|
||||
// f := excelize.NewFile()
|
||||
// defer func() {
|
||||
// _ = f.Close()
|
||||
// }()
|
||||
//
|
||||
// // 创建一个工作表
|
||||
// index, err := f.NewSheet("Sheet1")
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
//
|
||||
// // 设置工作簿的默认工作表
|
||||
// f.SetActiveSheet(index)
|
||||
//
|
||||
// // 单元格对齐样式
|
||||
// alignment := &excelize.Alignment{
|
||||
// Horizontal: "center",
|
||||
// Vertical: "center",
|
||||
// }
|
||||
//
|
||||
// // 单元格颜色填充样式
|
||||
// fill := excelize.Fill{
|
||||
// Type: "pattern",
|
||||
// Pattern: 1,
|
||||
// Color: []string{"#c9daf8"},
|
||||
// Shading: 0,
|
||||
// }
|
||||
//
|
||||
// // 第一行的左、右、下边框
|
||||
// border := []excelize.Border{
|
||||
// {
|
||||
// Type: "left,right,bottom",
|
||||
// Color: "",
|
||||
// Style: 1,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// // 工作表样式
|
||||
// style, err := f.NewStyle(
|
||||
// &excelize.Style{
|
||||
// Fill: fill,
|
||||
// Alignment: alignment,
|
||||
// Border: border,
|
||||
// },
|
||||
// )
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
//
|
||||
// // 依次设置每一列的列宽
|
||||
// widths = []int{18, 18, 18, 18, 18, 20, 23, 46, 18, 30, 30, 18, 18, 30, 18, 30}
|
||||
// for col, width := range widths {
|
||||
// // 获取列名
|
||||
// colName, err := excelize.ColumnNumberToName(col + 1)
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
//
|
||||
// // 设置列宽
|
||||
// err = f.SetColWidth("Sheet1", colName, colName, float64(width))
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
//
|
||||
// // 设置列背景颜色
|
||||
// err = f.SetCellStyle("Sheet1", colName+"1", colName+"1", style)
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 设置行高
|
||||
// err = f.SetRowStyle("Sheet1", 1, 10, style)
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
//
|
||||
// if err := f.SaveAs("output.xlsx"); err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
//
|
||||
// return true, nil
|
||||
// }
|
||||
|
||||
// HeaderCellData 表头内容
|
||||
type HeaderCellData struct {
|
||||
Value string // 值
|
||||
CellType string // 类型
|
||||
NumberFmt string // 格式化方式
|
||||
ColWidth int // 列宽
|
||||
}
|
||||
|
||||
func Export(header []HeaderCellData, data []interface{}) (*bytes.Buffer, error) {
|
||||
sheetName := "Sheet1"
|
||||
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
// 创建一个工作表
|
||||
index, err := f.NewSheet(sheetName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置工作簿的默认工作表
|
||||
f.SetActiveSheet(index)
|
||||
|
||||
// 设置工作表默认字体
|
||||
err = f.SetDefaultFont("宋体")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 统一单元格对齐样式
|
||||
alignment := &excelize.Alignment{
|
||||
Horizontal: "center",
|
||||
Vertical: "center",
|
||||
}
|
||||
|
||||
// 设置行高 35-第一行
|
||||
err = f.SetRowHeight(sheetName, 1, 35)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 处理工作表表头
|
||||
for c, cell := range header {
|
||||
// 获取列名
|
||||
colName, err := excelize.ColumnNumberToName(c + 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 添加单元格的值
|
||||
err = f.SetCellValue(sheetName, colName+"1", cell.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 单元格颜色填充样式
|
||||
fill := excelize.Fill{
|
||||
Type: "pattern",
|
||||
Pattern: 1,
|
||||
Color: []string{"#c9daf8"},
|
||||
Shading: 0,
|
||||
}
|
||||
|
||||
// 第一行的左、右、下边框
|
||||
border := []excelize.Border{
|
||||
{
|
||||
Type: "left",
|
||||
Color: "#000000",
|
||||
Style: 1,
|
||||
},
|
||||
{
|
||||
Type: "right",
|
||||
Color: "#000000",
|
||||
Style: 1,
|
||||
},
|
||||
{
|
||||
Type: "bottom",
|
||||
Color: "#000000",
|
||||
Style: 1,
|
||||
},
|
||||
}
|
||||
|
||||
// 设置单元格值类型和格式
|
||||
style, _ := f.NewStyle(&excelize.Style{
|
||||
Alignment: alignment, // 字体居中
|
||||
Fill: fill, // 背景颜色
|
||||
Border: border, // 边框
|
||||
})
|
||||
err = f.SetCellStyle(sheetName, colName+"1", colName+"1", style)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置列宽
|
||||
err = f.SetColWidth(sheetName, colName, colName, float64(cell.ColWidth))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 设置单元格格式
|
||||
row := len(data)
|
||||
for i, cell := range header {
|
||||
// 获取列名
|
||||
colName, err := excelize.ColumnNumberToName(i + 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 字体居中
|
||||
style := &excelize.Style{}
|
||||
style = &excelize.Style{
|
||||
Alignment: alignment,
|
||||
}
|
||||
|
||||
if cell.CellType == "float" {
|
||||
style.NumFmt = 2
|
||||
customNumFmt := "0.000"
|
||||
style.CustomNumFmt = &customNumFmt
|
||||
}
|
||||
|
||||
if cell.CellType == "date" {
|
||||
style.NumFmt = 22
|
||||
customNumFmt := "yyyy-mm-dd hh:mm:ss"
|
||||
style.CustomNumFmt = &customNumFmt
|
||||
}
|
||||
|
||||
newStyle, _ := f.NewStyle(style)
|
||||
err = f.SetCellStyle(sheetName, colName+"2", colName+strconv.Itoa(row), newStyle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 填充数据
|
||||
for r, rowData := range data {
|
||||
rv := reflect.ValueOf(rowData)
|
||||
for c := 0; c < rv.NumField(); c++ {
|
||||
cellValue := rv.Field(c).Interface()
|
||||
// 获取列名
|
||||
colName, err := excelize.ColumnNumberToName(c + 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
axis := colName + fmt.Sprintf("%d", r+2)
|
||||
|
||||
// 设置单元格值
|
||||
err = f.SetCellValue(sheetName, axis, cellValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置单元格值类型
|
||||
cellType := header[c].CellType
|
||||
|
||||
// 字体居中
|
||||
style := &excelize.Style{}
|
||||
style = &excelize.Style{
|
||||
Alignment: alignment,
|
||||
}
|
||||
|
||||
if cellType == "float" {
|
||||
style.NumFmt = 2
|
||||
customNumFmt := "0.000"
|
||||
style.CustomNumFmt = &customNumFmt
|
||||
}
|
||||
|
||||
if cellType == "date" {
|
||||
style.NumFmt = 22
|
||||
customNumFmt := "yyyy-mm-dd hh:mm:ss"
|
||||
style.CustomNumFmt = &customNumFmt
|
||||
}
|
||||
|
||||
newStyle, _ := f.NewStyle(style)
|
||||
err = f.SetCellStyle(sheetName, axis, axis, newStyle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置行高 35-第一行
|
||||
err = f.SetRowHeight(sheetName, r+2, 35)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer, err := f.WriteToBuffer()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buffer, nil
|
||||
|
||||
// 保存文件
|
||||
// if err := f.SaveAs("output.xlsx"); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return nil, errors.New("已导出文件")
|
||||
}
|
||||
124
utils/idCard.go
Normal file
124
utils/idCard.go
Normal file
@ -0,0 +1,124 @@
|
||||
// Package utils 身份证处理
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// GetCardAge 获取身份证年龄
|
||||
func GetCardAge(cardNum string) (int, error) {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
|
||||
// 解析身份证号中的出生日期
|
||||
birthDateStr := cardNum[6:14]
|
||||
birthYear, err := strconv.Atoi(birthDateStr[0:4])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
birthMonth, err := strconv.Atoi(birthDateStr[4:6])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 计算年龄
|
||||
age := now.Year() - birthYear
|
||||
if now.Month() < time.Month(birthMonth) {
|
||||
age--
|
||||
}
|
||||
|
||||
return age, nil
|
||||
}
|
||||
|
||||
// CheckCardNum 检测身份证号
|
||||
func CheckCardNum(cardNum string) (bool, error) {
|
||||
fmt.Println(cardNum)
|
||||
regex := `^(?:1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5])\d{4}(?:1[89]|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dxX]$`
|
||||
match, err := regexp.MatchString(regex, cardNum)
|
||||
fmt.Println(match)
|
||||
if !match || err != nil {
|
||||
return false, errors.New("身份证号错误")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetCardSex 获取身份证性别
|
||||
func GetCardSex(cardNum string) (int, error) {
|
||||
genderStr := cardNum[len(cardNum)-2 : len(cardNum)-1]
|
||||
genderNum, err := strconv.Atoi(genderStr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 判断性别
|
||||
if genderNum%2 == 0 {
|
||||
return 2, nil
|
||||
} else {
|
||||
return 1, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetMaskCardNum 身份证号码脱敏
|
||||
func GetMaskCardNum(cardNum string) string {
|
||||
if len(cardNum) != 18 {
|
||||
return cardNum
|
||||
}
|
||||
|
||||
// 获取身份证号前后部分
|
||||
frontPart := cardNum[0:6]
|
||||
backPart := cardNum[14:]
|
||||
|
||||
// 替换中间部分数字为 *
|
||||
middlePart := "****"
|
||||
|
||||
// 拼接新的身份证号
|
||||
maskedIDCard := frontPart + middlePart + backPart
|
||||
|
||||
return maskedIDCard
|
||||
}
|
||||
|
||||
// GetMaskCardName 身份证名字脱敏
|
||||
func GetMaskCardName(cardName string) string {
|
||||
// 判断姓名长度
|
||||
length := utf8.RuneCountInString(cardName)
|
||||
|
||||
// 判断是否是英文姓名
|
||||
isEnglish := strings.ContainsAny(cardName, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
if length == 2 {
|
||||
// 两个字符的姓名
|
||||
if isEnglish {
|
||||
// 英文姓名
|
||||
return string(cardName[0]) + "*"
|
||||
} else {
|
||||
// 中文姓名
|
||||
return string([]rune(cardName)[0]) + "*"
|
||||
}
|
||||
} else if length == 3 {
|
||||
// 三个字符的姓名
|
||||
if isEnglish {
|
||||
// 英文姓名
|
||||
return string(cardName[0]) + "*" + string(cardName[2])
|
||||
} else {
|
||||
// 中文姓名
|
||||
return string([]rune(cardName)[0]) + "*" + string([]rune(cardName)[2])
|
||||
}
|
||||
} else if length >= 4 {
|
||||
// 四个及以上字符的姓名
|
||||
if isEnglish {
|
||||
// 英文姓名
|
||||
return string(cardName[0]) + "*" + string(cardName[length-1])
|
||||
} else {
|
||||
// 中文姓名
|
||||
return string([]rune(cardName)[0]) + "*" + string([]rune(cardName)[length-1])
|
||||
}
|
||||
}
|
||||
|
||||
return cardName
|
||||
}
|
||||
3
utils/intToString.go
Normal file
3
utils/intToString.go
Normal file
@ -0,0 +1,3 @@
|
||||
package utils
|
||||
|
||||
// int转字符串
|
||||
40
utils/jwt.go
Normal file
40
utils/jwt.go
Normal file
@ -0,0 +1,40 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"knowledge/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
jwt.RegisteredClaims // v5版本新加的方法
|
||||
}
|
||||
|
||||
// NewJWT GenerateJWT 生成JWT
|
||||
func (t Token) NewJWT() (string, error) {
|
||||
ttl := time.Duration(config.C.Jwt.Ttl)
|
||||
|
||||
t.RegisteredClaims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(ttl * time.Hour)) // 过期时间24小时
|
||||
t.RegisteredClaims.IssuedAt = jwt.NewNumericDate(time.Now()) // 签发时间
|
||||
t.RegisteredClaims.NotBefore = jwt.NewNumericDate(time.Now()) // 生效时间
|
||||
|
||||
// 使用HS256签名算法
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, t)
|
||||
s, err := token.SignedString([]byte(config.C.Jwt.SignKey))
|
||||
|
||||
return s, err
|
||||
}
|
||||
|
||||
// ParseJwt 解析JWT
|
||||
func ParseJwt(authorization string) (*Token, error) {
|
||||
t, err := jwt.ParseWithClaims(authorization, &Token{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(config.C.Jwt.SignKey), nil
|
||||
})
|
||||
|
||||
if claims, ok := t.Claims.(*Token); ok && t.Valid {
|
||||
return claims, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
28
utils/logger.go
Normal file
28
utils/logger.go
Normal file
@ -0,0 +1,28 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
func LogJsonInfo(msg string, v interface{}) {
|
||||
jsonData, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
fmt.Println("Error marshaling struct to JSON:", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonString := string(jsonData)
|
||||
|
||||
global.Logger.WithFields(logrus.Fields{
|
||||
"data": jsonString,
|
||||
}).Info(msg)
|
||||
}
|
||||
|
||||
func LogJsonErr(msg string, v interface{}) {
|
||||
global.Logger.WithFields(logrus.Fields{
|
||||
"data": v,
|
||||
}).Errorf(msg)
|
||||
}
|
||||
89
utils/mask.go
Normal file
89
utils/mask.go
Normal file
@ -0,0 +1,89 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// MaskNameStr 用户名掩码
|
||||
func MaskNameStr(str string, maskType int) string {
|
||||
if str == "" {
|
||||
return str
|
||||
}
|
||||
|
||||
// 使用正则表达式判断是否包含中文字符
|
||||
chinesePattern := "[\u4e00-\u9fa5]+"
|
||||
isChinese, _ := regexp.MatchString(chinesePattern, str)
|
||||
|
||||
// 使用正则表达式判断是否包含英文字母
|
||||
englishPattern := "[A-Za-z]+"
|
||||
isEnglish, _ := regexp.MatchString(englishPattern, str)
|
||||
|
||||
// 判断是否包含中文字符
|
||||
if isChinese {
|
||||
// 按照中文字符计算长度
|
||||
strLen := utf8.RuneCountInString(str)
|
||||
|
||||
if strLen >= 3 {
|
||||
if maskType == 1 {
|
||||
// 三个字符或三个字符以上掐头取尾,中间用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
lastChar, _ := utf8.DecodeLastRuneInString(str)
|
||||
str = string(firstChar) + "*" + string(lastChar)
|
||||
} else {
|
||||
// 首字母保留,后两位用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "**"
|
||||
}
|
||||
} else if strLen == 2 {
|
||||
// 两个字符
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "*"
|
||||
}
|
||||
} else if isEnglish {
|
||||
// 按照英文字串计算长度
|
||||
strLen := utf8.RuneCountInString(str)
|
||||
|
||||
if strLen >= 3 {
|
||||
if maskType == 1 {
|
||||
// 三个字符或三个字符以上掐头取尾,中间用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
lastChar, _ := utf8.DecodeLastRuneInString(str)
|
||||
str = string(firstChar) + "*" + string(lastChar)
|
||||
} else {
|
||||
// 首字母保留,后两位用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "**"
|
||||
}
|
||||
} else if strLen == 2 {
|
||||
// 两个字符
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "*"
|
||||
}
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
// MaskPhoneStr 手机号、固话加密
|
||||
// 固话:0510-89754815 0510-8****815
|
||||
// 手机号:18221234158 18*******58
|
||||
func MaskPhoneStr(phone string) string {
|
||||
if phone == "" {
|
||||
return phone
|
||||
}
|
||||
|
||||
// 使用正则表达式匹配固定电话
|
||||
phonePattern := `(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)`
|
||||
isFixedLine := regexp.MustCompile(phonePattern).MatchString(phone)
|
||||
|
||||
if isFixedLine {
|
||||
// 匹配到固定电话
|
||||
// 替换匹配的部分为固定格式
|
||||
return regexp.MustCompile(`(0[0-9]{2,3}[\-]?[2-9])[0-9]{3,4}([0-9]{3}[\-]?[0-9]?)`).ReplaceAllString(phone, "$1****$2")
|
||||
} else {
|
||||
// 匹配到手机号
|
||||
// 替换匹配的部分为固定格式
|
||||
return regexp.MustCompile(`(1[0-9]{1})[0-9]{7}([0-9]{2})`).ReplaceAllString(phone, "$1*******$2")
|
||||
}
|
||||
}
|
||||
12
utils/regular.go
Normal file
12
utils/regular.go
Normal file
@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
import "regexp"
|
||||
|
||||
// RegexpMobile 手机号匹配
|
||||
func RegexpMobile(mobile string) bool {
|
||||
ok, err := regexp.MatchString(`^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$`, mobile)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ok
|
||||
}
|
||||
22
utils/replace.go
Normal file
22
utils/replace.go
Normal file
@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"knowledge/config"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RemoveOssDomain 去除oss地址中的前缀
|
||||
func RemoveOssDomain(url string) string {
|
||||
if url != "" {
|
||||
url = strings.Replace(url, config.C.Oss.OssCustomDomainName, "", 1)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
// AddOssDomain 增加oss地址中的前缀
|
||||
func AddOssDomain(url string) string {
|
||||
if url == "" {
|
||||
return ""
|
||||
}
|
||||
return config.C.Oss.OssCustomDomainName + url
|
||||
}
|
||||
15
utils/validator.go
Normal file
15
utils/validator.go
Normal file
@ -0,0 +1,15 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"knowledge/global"
|
||||
)
|
||||
|
||||
// Translate 检验并返回检验错误信息
|
||||
func Translate(err error) (errMsg string) {
|
||||
errs := err.(validator.ValidationErrors)
|
||||
for _, err := range errs {
|
||||
errMsg = err.Translate(global.Trans)
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user