提交 0985c1fb 编写于 作者: G Granty1

Migrating configuration files from json to yaml

上级 a0570c05
{
"casbin": {
"modelPath": "./resource/rbac_model.conf"
},
"jwt": {
"signingKey": "qmPlus"
},
"mysql": {
"username": "root",
"password": "Aa@6447985",
"path": "127.0.0.1:3306",
"dbname": "qmPlus",
"config": "charset=utf8\u0026parseTime=True\u0026loc=Local",
"maxIdleConns": 10,
"maxOpenConns": 100,
"logMode": true
},
"qiniu": {
"accessKey": "25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ",
"secretKey": "pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY"
},
"redis": {
"addr": "127.0.0.1:6379",
"password": "",
"db": 0
},
"system": {
"useMultipoint": false,
"env": "develop",
"addr": 8888
},
"captcha": {
"keyLong": 6,
"imgWidth": 120,
"imgHeight": 40
},
"log": {
"prefix": "[GIN-VUE-ADMIN]",
"logFile": false,
"stdout": "DEBUG",
"file": "WARNING"
}
}
\ No newline at end of file
# Gin-Vue-Admin Global Configuration
# casbin configuration
casbin:
model-path: './resource/rbac_model.conf'
# jwt configuration
jwt:
signing-key: 'qmPlus'
# mysql connect configuration
mysql:
username: root
#Aa@6447985
password: 'YINGL19980716.'
path: '127.0.0.1:3306'
db-name: 'qmPlus'
config: 'charset=utf8&parseTime=True&loc=Local'
max-idle-conns: 10
max-open-conns: 10
log-mode: true
# oss configuration
qiniu:
access-key: '25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ'
secret-key: 'pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
# redis configuration
redis:
addr: '127.0.0.1:6379'
passwprd: ''
db: 0
# system configuration
system:
use-multipoint: false
env: 'develop'
addr: 8888
# captcha configuration
captcha:
key-long: 6
img-width: 120
img-height: 40
# logger configuration
log:
prefix: '[GIN-VUE-ADMIN]'
log-file: true
stdout: 'DEBUG'
file: 'WARNING'
package config package config
type Server struct { type Server struct {
Mysql Mysql `json:"mysql"` Mysql `mapstructure:"mysql"`
Qiniu Qiniu `json:"qiniu"` Qiniu `mapstructure:"qiniu"`
Casbin Casbin `json:"casbin"` Casbin `mapstructure:"casbin"`
Redis Redis `json:"redis"` Redis `mapstructure:"redis"`
System System `json:"system"` System `mapstructure:"system"`
JWT JWT `json:"jwt"` JWT `mapstructure:"jwt"`
Captcha Captcha `json:"captcha"` Captcha `mapstructure:"captcha"`
Log Log `json:"log"` Log `mapstructure:"log"`
} }
type System struct { // 系统配置 type System struct {
UseMultipoint bool `json:"useMultipoint"` UseMultipoint bool `mapstructure:"use-multipoint"`
Env string `json:"env"` Env string `mapstructure:"env"`
Addr int `json:"addr"` Addr int `mapstructure:"addr"`
} }
type JWT struct { // jwt签名 type JWT struct {
SigningKey string `json:"signingKey"` SigningKey string `mapstructure:"signing-key"`
} }
type Casbin struct { //casbin配置 type Casbin struct {
ModelPath string `json:"modelPath"` // casbin model地址配置 ModelPath string `mapstructure:"model-path"`
} }
type Mysql struct { // mysql admin 数据库配置 type Mysql struct {
Username string `json:"username"` Username string `mapstructure:"username"`
Password string `json:"password"` Password string `mapstructure:"password"`
Path string `json:"path"` Path string `mapstructure:"path"`
Dbname string `json:"dbname"` Dbname string `mapstructure:"db-name"`
Config string `json:"config"` Config string `mapstructure:"config"`
MaxIdleConns int `json:"maxIdleConns"` MaxIdleConns int `mapstructure:"max-idle-conns"`
MaxOpenConns int `json:"maxOpenConns"` MaxOpenConns int `mapstructure:"max-open-conns"`
LogMode bool `json:"maxOpenConns"` LogMode bool `mapstructure:"log-mode"`
} }
type Redis struct { // Redis admin 数据库配置 type Redis struct {
Addr string `json:"addr"` Addr string `mapstructure:"addr"`
Password string `json:"password"` Password string `mapstructure:"password"`
DB int `json:"db"` DB int `mapstructure:"db"`
} }
type Qiniu struct { // 七牛 密钥配置 type Qiniu struct {
AccessKey string `json:"accessKey"` AccessKey string `mapstructure:"access-key"`
SecretKey string `json:"secretKey"` SecretKey string `mapstructure:"secret-key"`
} }
type Captcha struct { // 验证码配置 type Captcha struct {
KeyLong int `json:"keyLong"` KeyLong int `mapstructure:"key-long"`
ImgWidth int `json:"imgWidth"` ImgWidth int `mapstructure:"img-width"`
ImgHeight int `json:"imgHeight"` ImgHeight int `mapstructure:"img-height"`
} }
type Log struct { type Log struct {
// log 打印的前缀 Prefix string `mapstructure:"prefix"`
Prefix string `json:"prefix"` LogFile bool `mapstructure:"log-file"`
// 是否显示打印log的文件具体路径 Stdout string `mapstructure:"stdout"`
LogFile bool `json:"logFile"` File string `mapstructure:"file"`
// 在控制台打印log的级别, "" 默认不打印
Stdout string `json:"stdout"`
// 在文件中打印log的级别 "" 默认不打印
File string `json:"file"`
} }
...@@ -7,16 +7,17 @@ import ( ...@@ -7,16 +7,17 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const defaultConfigFile = "config.yaml"
func init() { func init() {
v := viper.New() v := viper.New()
v.SetConfigName("config") // 设置配置文件名 (不带后缀) v.SetConfigFile(defaultConfigFile)
v.AddConfigPath("./") // 第一个搜索路径 err := v.ReadInConfig()
v.SetConfigType("json")
err := v.ReadInConfig() // 搜索路径,并读取配置数据
if err != nil { if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err)) panic(fmt.Errorf("Fatal error config file: %s \n", err))
} }
v.WatchConfig() v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) { v.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("config file changed:", e.Name) fmt.Println("config file changed:", e.Name)
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册