1
0

feat: 合并Gin_Vue

This commit is contained in:
TsMask
2023-10-16 20:04:08 +08:00
parent 55fe1d534d
commit 05c7e9b9e8
213 changed files with 20338 additions and 311 deletions

View File

@@ -8,9 +8,9 @@ import (
sysMenuService "ems.agt/features/sys_menu/service"
sysRoleService "ems.agt/features/sys_role/service"
"ems.agt/lib/core/cache"
"ems.agt/lib/core/conf"
"ems.agt/lib/core/vo"
"ems.agt/lib/dborm"
srcConfig "ems.agt/src/framework/config"
)
// 登录缓存用户信息
@@ -35,7 +35,7 @@ func CacheLoginUser(user *dborm.User) {
}
// 是否管理员
if conf.IsAdmin(loginUser.UserID) {
if srcConfig.IsAdmin(loginUser.UserID) {
loginUser.Permissions = []string{"*:*:*"}
} else {
// 获取权限标识

View File

@@ -2,51 +2,35 @@ package conf
import (
"fmt"
"time"
"github.com/spf13/viper"
)
var v *viper.Viper
// 配置文件读取
func InitConfig(configFile string) {
v = viper.New()
// 设置配置文件路径
viper.SetConfigFile(configFile)
v.SetConfigFile(configFile)
// 读取配置文件
err := viper.ReadInConfig()
err := v.ReadInConfig()
if err != nil {
fmt.Printf("读取配置文件失败: %v \n", err)
return
}
// 记录程序开始运行的时间点
viper.Set("runTime", time.Now())
}
// RunTime 程序开始运行的时间
func RunTime() time.Time {
return viper.GetTime("runTime")
}
// Get 获取配置信息
//
// Get("framework.name")
func Get(key string) any {
return viper.Get(key)
return v.Get(key)
}
// IsAdmin 用户是否为管理员
func IsAdmin(userID string) bool {
if userID == "" {
return false
}
// 从本地配置获取user信息
// admins := Get("user.adminList").([]any)
admins := []string{"1", "2", "3"}
for _, s := range admins {
if s == userID {
return true
}
}
return false
// AllSettings 全部配置信息
func AllSettings() map[string]interface{} {
return v.AllSettings()
}

View File

@@ -8,8 +8,11 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"ems.agt/lib/core/vo"
commonConstants "ems.agt/src/framework/constants/common"
tokenConst "ems.agt/src/framework/constants/token"
"github.com/gorilla/mux"
)
@@ -101,13 +104,27 @@ func SaveUploadedFile(r *http.Request, dst string) error {
/// ==== 登录用户信息, 通过中间件后预置入
// Authorization 解析请求头
func Authorization(r *http.Request) string {
authHeader := r.Header.Get(tokenConst.HEADER_KEY)
if authHeader == "" {
return ""
}
// 拆分 Authorization 请求头,提取 JWT 令牌部分
arr := strings.Split(authHeader, tokenConst.HEADER_PREFIX)
if len(arr) == 2 && arr[1] == "" {
return ""
}
return arr[1]
}
// 定义自定义类型作为键
type ContextKey string
// LoginUser 登录用户信息需要Authorize中间件
func LoginUser(r *http.Request) (vo.LoginUser, error) {
// 上下文
v := r.Context().Value(ContextKey("LoginUser"))
v := r.Context().Value(ContextKey(commonConstants.CTX_LOGIN_USER))
if v != nil {
return v.(vo.LoginUser), nil
}