更新gf版本为v1.14.0 添加按钮权限 友情链接完善 cms模板选择

This commit is contained in:
yxh
2020-10-22 17:41:34 +08:00
parent c0e2e1efd9
commit 883f42eee6
28 changed files with 936 additions and 156 deletions
+11 -5
View File
@@ -77,9 +77,12 @@ func (c *CmsMenu) Add(r *ghttp.Request) {
if err != nil {
response.FailJson(true, r, err.Error())
}
//获取分类栏目模板
ListTemp, contentTemp := cms_service.GetCmsTemplate()
res := g.Map{
"parentList": menus,
"parentList": menus,
"listTemp": ListTemp,
"contentTemp": contentTemp,
}
response.SusJson(true, r, "添加栏目", res)
}
@@ -119,10 +122,13 @@ func (c *CmsMenu) Edit(r *ghttp.Request) {
if err != nil {
response.FailJson(true, r, err.Error())
}
//获取分类栏目模板
ListTemp, contentTemp := cms_service.GetCmsTemplate()
res := g.Map{
"menuInfo": menuInfo,
"parentList": menus,
"menuInfo": menuInfo,
"parentList": menus,
"listTemp": ListTemp,
"contentTemp": contentTemp,
}
response.SusJson(true, r, "修改栏目", res)
}
+15 -1
View File
@@ -27,6 +27,7 @@ func (c *Index) GetInfo(r *ghttp.Request) {
}
userInfo := gconv.Map(userEntity)
rolesList := make([]string, 0, 10)
var permissions []string
if userInfo != nil {
userId := userEntity.Id
delete(userInfo, "user_password")
@@ -44,6 +45,19 @@ func (c *Index) GetInfo(r *ghttp.Request) {
roleIds[k] = v.Id
}
userInfo["roles"] = roles
isSuperAdmin := false
//获取无需验证权限的用户id
for _, v := range service.NotCheckAuthAdminIds {
if gconv.Uint64(v) == userId {
isSuperAdmin = true
break
}
}
if isSuperAdmin {
permissions = []string{"*/*/*"}
} else {
permissions, err = user_service.GetPermissions(roleIds)
}
rolesList = name
} else {
g.Log().Error(err)
@@ -56,7 +70,7 @@ func (c *Index) GetInfo(r *ghttp.Request) {
result := g.Map{
"user": userInfo,
"roles": rolesList,
"permissions": nil,
"permissions": permissions,
}
response.SusJson(true, r, "ok", result)
+1 -1
View File
@@ -23,7 +23,7 @@ func (c *PlugLink) Add(r *ghttp.Request) {
response.FailJson(true, r, err.(*gvalid.Error).FirstString())
}
// 调用service中的添加函数添加链接
err = plug_link.AddSave(req)
err = plug_link_service.AddSavePlugLink(req)
if err != nil {
response.FailJson(true, r, err.Error())
}
@@ -38,6 +38,8 @@ type ReqAdd struct {
Status uint `p:"status" v:"in:0,1#状态只能包含0或1"`
CateAddress string `p:"cate_address"`
CateContent string `p:"content"`
ListTemplate string `p:"list_template"`
ContentTemplate string `p:"content_template"`
}
//修改请求参数
@@ -81,6 +83,8 @@ func AddSave(req *ReqAdd) (id int64, err error) {
entity.SeoDescription = req.InputSeoDescription
entity.CateAddress = req.CateAddress
entity.CateContent = req.CateContent
entity.ListTemplate = req.ListTemplate
entity.ContentTemplate = req.ContentTemplate
moreFields := g.Map{}
if req.Thumbnail != "" {
moreFields["thumb"] = req.Thumbnail
@@ -141,6 +145,8 @@ func EditSave(req *ReqEdit) (id int64, err error) {
entity.SeoDescription = req.InputSeoDescription
entity.CateAddress = req.CateAddress
entity.CateContent = req.CateContent
entity.ListTemplate = req.ListTemplate
entity.ContentTemplate = req.ContentTemplate
moreFields := g.Map{}
if req.Thumbnail != "" {
moreFields["thumb"] = req.Thumbnail
@@ -11,24 +11,26 @@ import (
// Entity is the golang structure for table cms_category.
type Entity struct {
Id uint64 `orm:"id,primary" json:"id"` // 分类id
ParentId int64 `orm:"parent_id" json:"parent_id"` // 分类父id
ModelId uint `orm:"model_id" json:"model_id"` // 模型ID
Status uint `orm:"status" json:"status"` // 状态,1:发布,0:不发布
DeleteTime uint `orm:"delete_time" json:"delete_time"` // 删除时间
ListOrder float64 `orm:"list_order" json:"list_order"` // 排序
Name string `orm:"name" json:"name"` // 分类名称
Alias string `orm:"alias" json:"alias"` // 栏目别名
Description string `orm:"description" json:"description"` // 分类描述
SeoTitle string `orm:"seo_title" json:"seo_title"` //
SeoKeywords string `orm:"seo_keywords" json:"seo_keywords"` //
SeoDescription string `orm:"seo_description" json:"seo_description"` //
ListTpl string `orm:"list_tpl" json:"list_tpl"` // 分类列表模板
OneTpl string `orm:"one_tpl" json:"one_tpl"` // 分类文章页模板
More string `orm:"more" json:"more"` // 扩展属性
CateType uint `orm:"cate_type" json:"cate_type"` // 分类类型
CateAddress string `orm:"cate_address" json:"cate_address"` // 跳转地址
CateContent string `orm:"cate_content" json:"cate_content"` // 单页内容
Id uint64 `orm:"id,primary" json:"id"` // 分类id
ParentId int64 `orm:"parent_id" json:"parent_id"` // 分类父id
ModelId uint `orm:"model_id" json:"model_id"` // 模型ID
Status uint `orm:"status" json:"status"` // 状态,1:发布,0:不发布
DeleteTime uint `orm:"delete_time" json:"delete_time"` // 删除时间
ListOrder float64 `orm:"list_order" json:"list_order"` // 排序
Name string `orm:"name" json:"name"` // 分类名称
Alias string `orm:"alias" json:"alias"` // 栏目别名
Description string `orm:"description" json:"description"` // 分类描述
SeoTitle string `orm:"seo_title" json:"seo_title"` //
SeoKeywords string `orm:"seo_keywords" json:"seo_keywords"` //
SeoDescription string `orm:"seo_description" json:"seo_description"` //
ListTpl string `orm:"list_tpl" json:"list_tpl"` // 分类列表模板
OneTpl string `orm:"one_tpl" json:"one_tpl"` // 分类文章页模板
More string `orm:"more" json:"more"` // 扩展属性
CateType uint `orm:"cate_type" json:"cate_type"` // 分类类型
CateAddress string `orm:"cate_address" json:"cate_address"` // 跳转地址
CateContent string `orm:"cate_content" json:"cate_content"` // 单页内容
ListTemplate string `orm:"list_template" json:"list_template"` //列表页模板
ContentTemplate string `orm:"content_template" json:"content_template"` //列表页模板
}
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
@@ -24,43 +24,47 @@ var (
Model = &arModel{g.DB("default").Table(Table).Safe()}
// Columns defines and stores column names for table cms_category.
Columns = struct {
Id string // 分类id
ParentId string // 分类父id
ModelId string // 模型ID
Status string // 状态,1:发布,0:不发布
DeleteTime string // 删除时间
ListOrder string // 排序
Name string // 分类名称
Alias string // 栏目别名
Description string // 分类描述
SeoTitle string //
SeoKeywords string //
SeoDescription string //
ListTpl string // 分类列表模板
OneTpl string // 分类文章页模板
More string // 扩展属性
CateType string // 分类类型
CateAddress string // 跳转地址
CateContent string // 单页内容
Id string // 分类id
ParentId string // 分类父id
ModelId string // 模型ID
Status string // 状态,1:发布,0:不发布
DeleteTime string // 删除时间
ListOrder string // 排序
Name string // 分类名称
Alias string // 栏目别名
Description string // 分类描述
SeoTitle string //
SeoKeywords string //
SeoDescription string //
ListTpl string // 分类列表模板
OneTpl string // 分类文章页模板
More string // 扩展属性
CateType string // 分类类型
CateAddress string // 跳转地址
CateContent string // 单页内容
ListTemplate string //列表页模板
ContentTemplate string //内容页模板
}{
Id: "id",
ParentId: "parent_id",
ModelId: "model_id",
Status: "status",
DeleteTime: "delete_time",
ListOrder: "list_order",
Name: "name",
Alias: "alias",
Description: "description",
SeoTitle: "seo_title",
SeoKeywords: "seo_keywords",
SeoDescription: "seo_description",
ListTpl: "list_tpl",
OneTpl: "one_tpl",
More: "more",
CateType: "cate_type",
CateAddress: "cate_address",
CateContent: "cate_content",
Id: "id",
ParentId: "parent_id",
ModelId: "model_id",
Status: "status",
DeleteTime: "delete_time",
ListOrder: "list_order",
Name: "name",
Alias: "alias",
Description: "description",
SeoTitle: "seo_title",
SeoKeywords: "seo_keywords",
SeoDescription: "seo_description",
ListTpl: "list_tpl",
OneTpl: "one_tpl",
More: "more",
CateType: "cate_type",
CateAddress: "cate_address",
CateContent: "cate_content",
ListTemplate: "list_template",
ContentTemplate: "content_template",
}
)
+15
View File
@@ -150,3 +150,18 @@ func SelectListByPage(req *SelectPageReq) (total int, page int64, list []*ListEn
}
return total, page, list, nil
}
// 获取size条状态为status的广告信息,优先按排序序号排序,其次按时间倒序(status 0停用 1正常)
func GetSizeAd(size int, status int, typeId int) ([]*Entity, error) {
model := Model
model = model.Where("ad_open = ?", status)
if typeId != 0 {
model = model.Where("ad_adtypeid = ?", typeId)
}
entity, err := model.Order("ad_sort asc,ad_addtime desc").Limit(size).All()
if err != nil {
g.Log().Error(err)
return nil, gerror.New("查询广告信息失败")
}
return entity, nil
}
+26 -7
View File
@@ -14,13 +14,16 @@ import (
// AddReq 用于存储新增链接请求的请求参数
type AddReq struct {
LinkName string `p:"linkName" v:"required#名称不能为空"` // 链接名称
LinkUrl string `p:"linkUrl"` // 链接URL
LinkTarget string `p:"linkTarget"` // 打开方式
LinkTypeID int `p:"linkTypeID"` // 所属栏目ID
LinkQQ string `p:"linkQQ"` // 联系QQ
LinkOrder int64 `p:"linkOrder"` // 排序
LinkOpen int `p:"linkOpen"` // 0禁用1启用(是否审核)
LinkName string `p:"linkName" v:"required#名称不能为空"` // 链接名称
LinkUrl string `p:"linkUrl" v:"required#名称不能为空"` // 链接URL
LinkTarget string `p:"linkTarget" ` // 打开方式
LinkTypeID int `p:"linkTypeID"` // 所属栏目ID
LinkQQ string `p:"linkQQ" v:"required#名称不能为空"` // 联系QQ
LinkOrder int64 `p:"linkOrder"` // 排序
LinkOpen int `p:"linkOpen"` // 0禁用1启用(是否审核)
LinkUsername string `p:"linkUsername" v:"required#名称不能为空"` // 申请友情链接的联系人
LinkEmail string `p:"linkEmail"` // 联系邮箱
LinkRemark string `p:"linkRemark"` // 申请友情链接时的备注
}
// EditReq 用于存储修改广告位请求参数
@@ -66,6 +69,9 @@ func AddSave(req *AddReq) error {
entity.LinkAddtime = int(gtime.Timestamp()) // 添加时间
entity.LinkOrder = req.LinkOrder
entity.LinkOpen = req.LinkOpen
entity.LinkUsername = req.LinkUsername
entity.LinkEmail = req.LinkEmail
entity.LinkRemark = req.LinkRemark
// 保存实体
_, err := entity.Insert()
if err != nil {
@@ -100,6 +106,9 @@ func EditSave(editReq *EditReq) error {
entity.LinkQq = editReq.LinkQQ
entity.LinkOrder = editReq.LinkOrder
entity.LinkOpen = editReq.LinkOpen
entity.LinkUsername = editReq.LinkUsername
entity.LinkEmail = editReq.LinkEmail
entity.LinkRemark = editReq.LinkRemark
_, err = entity.Update()
if err != nil {
g.Log().Error(err)
@@ -147,3 +156,13 @@ func SelectListByPage(req *SelectPageReq) (total int, page int64, list []*ListEn
}
return total, page, list, nil
}
// 按链接分类查询当前分类下的size条最新链接(status:1启用,0未启用,优先序号排序,其次时间倒序)
func ListByTypeId(typeId int, size int, status int) (list []*Entity, err error) {
list, err = Model.Where("link_typeid = ?", typeId).And("link_open = ?", status).Fields("link_name,link_url,link_target").Order("link_order asc,link_addtime desc").Limit(size).All()
if err != nil {
g.Log().Error(err)
return nil, gerror.New("按分类查询链接出错")
}
return list, nil
}
+12 -9
View File
@@ -11,15 +11,18 @@ import (
// Entity is the golang structure for table plug_link.
type Entity struct {
LinkId int `orm:"link_id,primary" json:"link_id"` //
LinkName string `orm:"link_name" json:"link_name"` // 链接名称
LinkUrl string `orm:"link_url" json:"link_url"` // 链接URL
LinkTarget string `orm:"link_target" json:"link_target"` // 打开方式
LinkTypeid int `orm:"link_typeid" json:"link_typeid"` // 所属栏目ID
LinkQq string `orm:"link_qq" json:"link_qq"` // 联系QQ
LinkOrder int64 `orm:"link_order" json:"link_order"` // 排序
LinkAddtime int `orm:"link_addtime" json:"link_addtime"` // 添加时间
LinkOpen int `orm:"link_open" json:"link_open"` // 0禁用1启用
LinkId int `orm:"link_id,primary" json:"link_id"` //
LinkName string `orm:"link_name" json:"link_name"` // 链接名称
LinkUrl string `orm:"link_url" json:"link_url"` // 链接URL
LinkTarget string `orm:"link_target" json:"link_target"` // 打开方式
LinkTypeid int `orm:"link_typeid" json:"link_typeid"` // 所属栏目ID
LinkQq string `orm:"link_qq" json:"link_qq"` // 联系QQ
LinkOrder int64 `orm:"link_order" json:"link_order"` // 排序
LinkAddtime int `orm:"link_addtime" json:"link_addtime"` // 添加时间
LinkOpen int `orm:"link_open" json:"link_open"` // 0禁用1启用
LinkUsername string `orm:"link_username" json:"link_username"` // 申请友情链接的联系人
LinkEmail string `orm:"link_email" json:"link_email"` // 联系邮箱
LinkRemark string `orm:"link_remark" json:"link_remark"` // 申请友情链接时的备注
}
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+24 -18
View File
@@ -24,25 +24,31 @@ var (
Model = &arModel{g.DB("default").Table(Table).Safe()}
// Columns defines and stores column names for table plug_link.
Columns = struct {
LinkId string //
LinkName string // 链接名称
LinkUrl string // 链接URL
LinkTarget string // 打开方式
LinkTypeid string // 所属栏目ID
LinkQq string // 联系QQ
LinkOrder string // 排序
LinkAddtime string // 添加时间
LinkOpen string // 0禁用1启用
LinkId string //
LinkName string // 链接名称
LinkUrl string // 链接URL
LinkTarget string // 打开方式
LinkTypeid string // 所属栏目ID
LinkQq string // 联系QQ
LinkOrder string // 排序
LinkAddtime string // 添加时间
LinkOpen string // 0禁用1启用
LinkUsername string // 申请友情链接的联系人
LinkEmail string // 联系邮箱
LinkRemark string // 申请友情链接时的备注
}{
LinkId: "link_id",
LinkName: "link_name",
LinkUrl: "link_url",
LinkTarget: "link_target",
LinkTypeid: "link_typeid",
LinkQq: "link_qq",
LinkOrder: "link_order",
LinkAddtime: "link_addtime",
LinkOpen: "link_open",
LinkId: "link_id",
LinkName: "link_name",
LinkUrl: "link_url",
LinkTarget: "link_target",
LinkTypeid: "link_typeid",
LinkQq: "link_qq",
LinkOrder: "link_order",
LinkAddtime: "link_addtime",
LinkOpen: "link_open",
LinkUsername: "link_username",
LinkEmail: "link_email",
LinkRemark: "link_remark",
}
)
+1 -1
View File
@@ -16,7 +16,7 @@ type StatusReq struct {
//重置用户密码状态参数
type ResetPwdReq struct {
Id int `p:"userId" v:"required#用户id不能为空"`
Id uint64 `p:"userId" v:"required#用户id不能为空"`
Password string `p:"password" v:"required|password#密码不能为空|密码以字母开头,只能包含字母、数字和下划线,长度在6~18之间"`
}
+16 -2
View File
@@ -30,7 +30,7 @@ func GetIsMenuList() ([]*auth_rule.Entity, error) {
return gList, nil
}
//获取isMenu=1且status=1的菜单列表
//获取isMenu=0|1且status=1的菜单列表
func GetIsMenuStatusList() ([]*auth_rule.Entity, error) {
list, err := GetMenuList()
if err != nil {
@@ -45,6 +45,21 @@ func GetIsMenuStatusList() ([]*auth_rule.Entity, error) {
return gList, nil
}
//获取所有按钮isMenu=2 且status=1的菜单列表
func GetIsButtonStatusList() ([]*auth_rule.Entity, error) {
list, err := GetMenuList()
if err != nil {
return nil, err
}
var gList = make([]*auth_rule.Entity, 0, len(list))
for _, v := range list {
if v.MenuType == 2 && v.Status == 1 {
gList = append(gList, v)
}
}
return gList, nil
}
//获取status==1的菜单列表
func GetMenuIsStatusList() ([]*auth_rule.Entity, error) {
list, err := GetMenuList()
@@ -80,7 +95,6 @@ func GetMenuListSearch(req *auth_rule.ReqSearch) (list []*auth_rule.Entity, err
}
list = tmpList
}
g.Log().Debug(list)
return
}
+24
View File
@@ -9,6 +9,8 @@ import (
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gfile"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv"
)
@@ -149,3 +151,25 @@ func GetModelIdByCateIds(ids []int) (modelId uint, err error) {
}
return
}
//获取分类模板
func GetCmsTemplate() ([]string, []string) {
pathArr := g.Cfg().GetArray("viewer.paths")
var listTemplates []string
var contentTemplates []string
for _, p := range pathArr {
path := gconv.String(p) + "/cms"
if gfile.IsDir(path) {
path = gfile.Abs(path)
cmsPath, _ := gfile.ScanDirFile(path, "*", true)
for _, cp := range cmsPath {
if gstr.ContainsI(cp, "list") {
listTemplates = append(listTemplates, gstr.TrimLeft(gstr.ReplaceByArray(cp, []string{path, "", "\\", "/"}), "/"))
} else if gstr.ContainsI(cp, "content") {
contentTemplates = append(contentTemplates, gstr.TrimLeft(gstr.ReplaceByArray(cp, []string{path, "", "\\", "/"}), "/"))
}
}
}
}
return listTemplates, contentTemplates
}
@@ -28,3 +28,8 @@ func GetPlugLinkByID(id int64) (*plug_link.Entity, error) {
func SelectPlugLinkListByPage(req *plug_link.SelectPageReq) (total int, page int64, list []*plug_link.ListEntity, err error) {
return plug_link.SelectListByPage(req)
}
// 按链接分类查询当前分类下的size条最新链接(status:1启用,0未启用,优先序号排序,其次时间倒序)
func ListByTypeId(typeId int, size int, status int) (list []*plug_link.Entity, err error) {
return plug_link.ListByTypeId(typeId, size, status)
}
+5
View File
@@ -28,3 +28,8 @@ func GetPlugAdByID(id int64) (*plug_ad.Entity, error) {
func SelectPlugAdListByPage(req *plug_ad.SelectPageReq) (total int, page int64, list []*plug_ad.ListEntity, err error) {
return plug_ad.SelectListByPage(req)
}
// 获取size条状态为status的广告信息,优先按排序序号排序,其次按时间倒序(status 0停用 1正常)
func GetSizeAd(size int, status int, typeId int) ([]*plug_ad.Entity, error) {
return plug_ad.GetSizeAd(size, status, typeId)
}
+31 -2
View File
@@ -53,7 +53,7 @@ func UpdatePwd(r *ghttp.Request, data *UpdatePwdReq) error {
}
return ResetUserPwd(&user.ResetPwdReq{
Id: currentUser["id"].(int),
Id: gconv.Uint64(currentUser["id"]),
Password: data.NewPassword,
})
}
@@ -140,7 +140,7 @@ func GetAdminList(req *user.SearchReq) (total, page int, userList []*user.Entity
if req.DeptId != "" {
depts, err = sys_dept.GetList(&sys_dept.SearchParams{Status: "1"})
if err != nil {
g.Log().Debug(err)
g.Log().Error(err)
err = gerror.New("获取部门信息失败")
return
}
@@ -168,6 +168,9 @@ func GetAdminRole(userId uint64, allRoleList []*role.Entity) (roles []*role.Enti
roles = append(roles, v)
}
}
if len(roles) == len(roleIds) {
break
}
}
return
}
@@ -284,3 +287,29 @@ func ResetUserPwd(req *user.ResetPwdReq) error {
req.Password = utils.EncryptCBC(gconv.String(req.Password), utils.AdminCbcPublicKey)
return user.ResetUserPwd(req)
}
func GetPermissions(roleIds []uint) ([]string, error) {
//获取角色对应的菜单id
enforcer, err := casbin_adapter_service.GetEnforcer()
if err != nil {
return nil, err
}
menuIds := map[int64]int64{}
for _, roleId := range roleIds {
//查询当前权限
gp := enforcer.GetFilteredPolicy(0, fmt.Sprintf("g_%d", roleId))
for _, p := range gp {
mid := gconv.Int64(gstr.SubStr(p[1], 2))
menuIds[mid] = mid
}
}
//获取所有开启的按钮
allButtons, err := auth_service.GetIsButtonStatusList()
userButtons := make([]string, 0, len(allButtons))
for _, button := range allButtons {
if _, ok := menuIds[gconv.Int64(button.Id)]; gstr.Equal(button.Condition, "nocheck") || ok {
userButtons = append(userButtons, button.Name)
}
}
return userButtons, nil
}
+28 -16
View File
@@ -25,7 +25,7 @@ func (c *CacheTagService) cacheTagKey(key interface{}, tag interface{}) {
c.setTagKey(tag)
if c.tagKey != nil {
tagValue := []interface{}{key}
value := gcache.Get(c.tagKey)
value, _ := gcache.Get(c.tagKey)
if value != nil {
keyValue := gconv.SliceAny(value)
for _, v := range keyValue {
@@ -60,7 +60,8 @@ func (c *CacheTagService) SetIfNotExist(key interface{}, value interface{}, dura
tagSetMux.Lock()
defer tagSetMux.Unlock()
c.cacheTagKey(key, tag)
return gcache.SetIfNotExist(key, value, duration)
v, _ := gcache.SetIfNotExist(key, value, duration)
return v
}
// Sets batch sets cache with tagKey-value pairs by <data>, which is expired after <duration>.
@@ -82,7 +83,8 @@ func (c *CacheTagService) Sets(data map[interface{}]interface{}, duration time.D
// Get returns the value of <tagKey>.
// It returns nil if it does not exist or its value is nil.
func (c *CacheTagService) Get(key interface{}) interface{} {
return gcache.Get(key)
v, _ := gcache.Get(key)
return v
}
// GetOrSet returns the value of <tagKey>,
@@ -94,17 +96,19 @@ func (c *CacheTagService) GetOrSet(key interface{}, value interface{}, duration
tagSetMux.Lock()
defer tagSetMux.Unlock()
c.cacheTagKey(key, tag)
return gcache.GetOrSet(key, value, duration)
v, _ := gcache.GetOrSet(key, value, duration)
return v
}
// GetOrSetFunc returns the value of <tagKey>, or sets <tagKey> with result of function <f>
// and returns its result if <tagKey> does not exist in the cache. The tagKey-value pair expires
// after <duration>. It does not expire if <duration> <= 0.
func (c *CacheTagService) GetOrSetFunc(key interface{}, f func() interface{}, duration time.Duration, tag interface{}) interface{} {
func (c *CacheTagService) GetOrSetFunc(key interface{}, f func() (interface{}, error), duration time.Duration, tag interface{}) interface{} {
tagSetMux.Lock()
defer tagSetMux.Unlock()
c.cacheTagKey(key, tag)
return gcache.GetOrSetFunc(key, f, duration)
v, _ := gcache.GetOrSetFunc(key, f, duration)
return v
}
// GetOrSetFuncLock returns the value of <tagKey>, or sets <tagKey> with result of function <f>
@@ -112,26 +116,29 @@ func (c *CacheTagService) GetOrSetFunc(key interface{}, f func() interface{}, du
// after <duration>. It does not expire if <duration> <= 0.
//
// Note that the function <f> is executed within writing mutex lock.
func (c *CacheTagService) GetOrSetFuncLock(key interface{}, f func() interface{}, duration time.Duration, tag interface{}) interface{} {
func (c *CacheTagService) GetOrSetFuncLock(key interface{}, f func() (interface{}, error), duration time.Duration, tag interface{}) interface{} {
tagSetMux.Lock()
defer tagSetMux.Unlock()
c.cacheTagKey(key, tag)
return gcache.GetOrSetFuncLock(key, f, duration)
v, _ := gcache.GetOrSetFuncLock(key, f, duration)
return v
}
// Contains returns true if <tagKey> exists in the cache, or else returns false.
func (c *CacheTagService) Contains(key interface{}) bool {
return gcache.Contains(key)
v, _ := gcache.Contains(key)
return v
}
// Remove deletes the <tagKey> in the cache, and returns its value.
func (c *CacheTagService) Remove(key interface{}) interface{} {
return gcache.Remove(key)
v, _ := gcache.Remove(key)
return v
}
// Removes deletes <keys> in the cache.
func (c *CacheTagService) Removes(keys []interface{}) {
gcache.Removes(keys)
gcache.Remove(keys...)
}
// Remove deletes the <tag> in the cache, and returns its value.
@@ -157,25 +164,30 @@ func (c *CacheTagService) RemoveByTags(tag []interface{}) {
// Data returns a copy of all tagKey-value pairs in the cache as map type.
func (c *CacheTagService) Data() map[interface{}]interface{} {
return gcache.Data()
v, _ := gcache.Data()
return v
}
// Keys returns all keys in the cache as slice.
func (c *CacheTagService) Keys() []interface{} {
return gcache.Keys()
v, _ := gcache.Keys()
return v
}
// KeyStrings returns all keys in the cache as string slice.
func (c *CacheTagService) KeyStrings() []string {
return gcache.KeyStrings()
v, _ := gcache.KeyStrings()
return v
}
// Values returns all values in the cache as slice.
func (c *CacheTagService) Values() []interface{} {
return gcache.Values()
v, _ := gcache.Values()
return v
}
// Size returns the size of the cache.
func (c *CacheTagService) Size() int {
return gcache.Size()
v, _ := gcache.Size()
return v
}
+1 -1
View File
@@ -87,7 +87,7 @@ func GetOnlineInfo(token string) g.Map {
cacheKey := boot.AdminGfToken.CacheKey + userKey
switch boot.AdminGfToken.CacheMode {
case gtoken.CacheModeCache:
userCacheValue := gcache.Get(cacheKey)
userCacheValue, _ := gcache.Get(cacheKey)
if userCacheValue == nil {
return nil
}