Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
bfda990c
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
10 个月 前同步成功
通知
324
Star
18154
Fork
5505
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bfda990c
编写于
9月 23, 2020
作者:
Sliver_Horn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化 优先级: 命令行 > 环境变量 > 默认值 功能
上级
ab4fa15f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
16 deletion
+21
-16
server/config.yaml
server/config.yaml
+1
-0
server/config/config.go
server/config/config.go
+2
-1
server/core/config.go
server/core/config.go
+18
-15
未找到文件。
server/config.yaml
浏览文件 @
bfda990c
...
...
@@ -78,6 +78,7 @@ system:
db-type
:
"
mysql"
# support mysql/postgresql/sqlite/sqlserver
need-init-data
:
false
error-to-email
:
false
config-env
:
"
GVA_CONFIG"
# captcha configuration
captcha
:
...
...
server/config/config.go
浏览文件 @
bfda990c
...
...
@@ -22,7 +22,8 @@ type System struct {
Addr
int
`mapstructure:"addr" json:"addr" yaml:"addr"`
DbType
string
`mapstructure:"db-type" json:"dbType" yaml:"db-type"`
NeedInitData
bool
`mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"`
ErrorToEmail
bool
`mapstructure:"error-to-email" json:"errorToEmail" yaml:"error-to-email"`
ErrorToEmail
bool
`mapstructure:"error-to-email" json:"errorToEmail" yaml:"error-to-email"`
ConfigEnv
string
`mapstructure:"config-env" json:"configEnv" yaml:"config-env"`
}
type
JWT
struct
{
...
...
server/core/config.go
浏览文件 @
bfda990c
package
core
import
(
"flag"
"fmt"
"gin-vue-admin/global"
_
"gin-vue-admin/packfile"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"
github.com/spf13/pflag
"
"
os
"
)
var
config
string
const
defaultConfigFile
=
"config.yaml"
func
init
()
{
pflag
.
StringP
(
"configFile"
,
"c"
,
""
,
"choose config file."
)
p
flag
.
Parse
()
// 优先级: 命令行 > 环境变量 > 默认值
v
:=
viper
.
New
()
v
.
BindPFlags
(
pflag
.
CommandLin
e
)
v
.
SetEnvPrefix
(
"gva"
)
v
.
BindEnv
(
"configFile"
)
// GVA_CONFIGFILE
configFile
:=
v
.
GetString
(
"configFile"
)
if
configFile
==
""
{
configFile
=
defaultConfigFile
flag
.
StringVar
(
&
config
,
"c"
,
""
,
"choose config file."
)
flag
.
Parse
()
if
config
==
""
{
// 优先级: 命令行 > 环境变量 > 默认值
if
configEnv
:=
os
.
Getenv
(
global
.
GVA_CONFIG
.
System
.
ConfigEnv
);
configEnv
==
""
{
config
=
defaultConfigFile
fmt
.
Printf
(
"您正在使用config的默认值,config的路径为%v
\n
"
,
defaultConfigFil
e
)
}
else
{
config
=
configEnv
fmt
.
Printf
(
"您正在使用GVA_CONFIG环境变量,config的路径为%v
\n
"
,
config
)
}
}
else
{
fmt
.
Printf
(
"您正在使用命令行的-c参数传递的值,config的路径为%v
\n
"
,
config
)
}
v
.
SetConfigFile
(
config
File
)
v
:=
viper
.
New
()
v
.
SetConfigFile
(
config
)
err
:=
v
.
ReadInConfig
()
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"Fatal error config file: %s
\n
"
,
err
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录