feat: 合并Gin_Vue
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user