代码拉取完成,页面将自动刷新
package xlink
import (
"errors"
"time"
"gitee.com/xiaoyutab/xgotool/individual/xcache"
)
// 查询连接信息(只查询在有效期内的、有效的连接)
//
// id 连接ID
// code 连接code码
func Find(id uint, code string) (*Link, error) {
if id == 0 && code == "" {
return nil, errors.New("连接参数传输")
}
link := Link{}
cache_key_id := xcache.Key("xlink.info", id)
cache_key_code := xcache.Key("xlink.info", code)
if xcache.Exists(cache_key_id) {
if err := xcache.GetStruct(cache_key_id, &link); err == nil {
return &link, nil
}
}
if xcache.Exists(cache_key_code) {
if err := xcache.GetStruct(cache_key_code, &link); err == nil {
return &link, nil
}
}
if _default.DB == nil {
return nil, errors.New("数据库未连接")
}
err := _default.DB.Table(_default.LinkName).
Where("end_date >= ?", time.Now().Format(time.DateOnly)).
Where("status", 0).
Where("is_deleted", 0).
Where("( id = ? or codes = ? )", id, code).Find(&link).Error
if err != nil {
return nil, err
}
if link.Id == 0 {
return nil, errors.New("连接不存在")
}
xcache.SetStruct(cache_key_id, link)
xcache.SetStruct(cache_key_code, link)
return &link, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。