hotgo/hotgo-server/app/utils/auth_util.go
2022-02-25 17:11:17 +08:00

66 lines
1.3 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package utils
import (
"context"
"github.com/gogf/gf/v2/frame/g"
)
// 权限认证类
var Auth = new(auth)
type auth struct{}
//
//  @Title  是否是不需要验证权限的路由地址
//  @Description
//  @Author  Ms <133814250@qq.com>
//  @Param   ctx
//  @Param   path
//  @Return  bool
//
func (util *auth) IsExceptAuth(ctx context.Context, path string) bool {
var pathList []string
except, _ := g.Cfg().Get(ctx, "router.admin.exceptAuth")
pathList = except.Strings()
for i := 0; i < len(pathList); i++ {
if Charset.IsExists(pathList[i], path) {
return true
}
}
return false
}
//
//  @Title  是否是不需要登录的路由地址
//  @Description
//  @Author  Ms <133814250@qq.com>
//  @Param   ctx
//  @Param   path
//  @Return  bool
//
func (util *auth) IsExceptLogin(ctx context.Context, path string) bool {
var pathList []string
except, _ := g.Cfg().Get(ctx, "router.admin.exceptLogin")
pathList = except.Strings()
for i := 0; i < len(pathList); i++ {
if Charset.IsExists(pathList[i], path) {
return true
}
}
return false
}