1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
create.go 961 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2024-04-30 10:12 . 调整xcron和xcache的目录结构
package xlink
import (
"errors"
"time"
"gitee.com/xiaoyutab/xgotool/individual/xcache"
"gitee.com/xiaoyutab/xgotool/xstring"
)
// 创建连接信息
func Create(bat *Link) error {
if _default.DB == nil {
return errors.New("数据库未连接")
}
if bat.UserId == 0 {
return errors.New("连接创建人ID不能为空")
}
if bat.Uri == "" {
return errors.New("跳转网址不能为空")
}
for {
if bat.Codes == "" {
bat.Codes = xstring.Random(6)
}
if _, err := Find(0, bat.Codes); err != nil {
break
}
}
if bat.EndDate == "" {
bat.EndDate = time.Now().AddDate(0, 1, 0).Format(time.DateOnly)
}
if bat.CreatedAt == "" {
bat.CreatedAt = time.Now().Format(time.DateTime)
}
bat.UpdatedAt = time.Now().Format(time.DateTime)
err := _default.DB.Save(bat).Error
if err != nil {
return err
}
// 缓存写入
xcache.Remove(xcache.Key("xlink.info", bat.Id))
xcache.Remove(xcache.Key("xlink.info", bat.Codes))
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.16

搜索帮助

344bd9b3 5694891 D2dac590 5694891