mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
添加jwt配置
This commit is contained in:
+16
-8
@@ -7,14 +7,14 @@ import (
|
|||||||
|
|
||||||
var cfgDatabase *viper.Viper
|
var cfgDatabase *viper.Viper
|
||||||
var cfgApplication *viper.Viper
|
var cfgApplication *viper.Viper
|
||||||
var cfgRedisConn *viper.Viper
|
var cfgJwt *viper.Viper
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
viper.SetConfigName("settings") // name of config file (without extension)
|
viper.SetConfigName("settings")
|
||||||
viper.AddConfigPath("./config") // optionally look for config in the working directory
|
viper.AddConfigPath("./config")
|
||||||
err := viper.ReadInConfig() // Find and read the config file
|
err := viper.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err) // Handle errors reading the config file
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgDatabase = viper.Sub("settings.database")
|
cfgDatabase = viper.Sub("settings.database")
|
||||||
@@ -29,11 +29,19 @@ func init() {
|
|||||||
}
|
}
|
||||||
ApplicationConfig = InitApplication(cfgApplication)
|
ApplicationConfig = InitApplication(cfgApplication)
|
||||||
|
|
||||||
|
cfgJwt = viper.Sub("settings.jwt")
|
||||||
|
if cfgJwt == nil {
|
||||||
|
panic("config not found settings.jwt")
|
||||||
|
}
|
||||||
|
JwtConfig = InitJwt(cfgJwt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetApplicationIsInit() {
|
func SetApplicationIsInit() {
|
||||||
viper.AddConfigPath("./config")
|
SetConfig("./config","settings.application.isInit", false)
|
||||||
viper.Set("settings.application.isInit", false)
|
}
|
||||||
|
|
||||||
|
func SetConfig(configPath string,key string,value interface{}){
|
||||||
|
viper.AddConfigPath(configPath)
|
||||||
|
viper.Set(key, value)
|
||||||
viper.WriteConfig()
|
viper.WriteConfig()
|
||||||
}
|
}
|
||||||
|
|||||||
+577
-989
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Jwt struct {
|
||||||
|
Secret string
|
||||||
|
Timeout int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitJwt(cfg *viper.Viper) *Jwt {
|
||||||
|
return &Jwt{
|
||||||
|
Secret: cfg.GetString("secret"),
|
||||||
|
Timeout: cfg.GetInt64("timeout"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var JwtConfig = new(Jwt)
|
||||||
+3
-2
@@ -4,16 +4,17 @@ settings:
|
|||||||
envmsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!\U0001F600\U0001F600\U0001F600"
|
envmsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!\U0001F600\U0001F600\U0001F600"
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
isinit: false
|
isinit: false
|
||||||
jwtsecret: 123abc
|
|
||||||
logpath: temp/logs/log.txt
|
logpath: temp/logs/log.txt
|
||||||
name: testApp
|
name: testApp
|
||||||
port: 8000
|
port: 8000
|
||||||
readtimeout: 1
|
readtimeout: 1
|
||||||
writertimeout: 2
|
writertimeout: 2
|
||||||
|
jwt:
|
||||||
|
secret: go-admin
|
||||||
|
timeout: 3600
|
||||||
database:
|
database:
|
||||||
database: goadmin
|
database: goadmin
|
||||||
dbtype: mysql
|
dbtype: mysql
|
||||||
host: 127.0.0.1
|
|
||||||
password: 123456
|
password: 123456
|
||||||
port: 3306
|
port: 3306
|
||||||
username: root
|
username: root
|
||||||
|
|||||||
Reference in New Issue
Block a user