Skip to content

Commit 7a2c28a

Browse files
author
piexlMax(奇淼
committed
Merge remote-tracking branch 'origin/dev-281' into dev-281
2 parents 0e93e57 + e2d7f6a commit 7a2c28a

File tree

6 files changed

+49
-40
lines changed

6 files changed

+49
-40
lines changed

Diff for: server/core/viper.go

+42-37
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,26 @@ package core
33
import (
44
"flag"
55
"fmt"
6-
"github.com/flipped-aurora/gin-vue-admin/server/core/internal"
7-
"github.com/gin-gonic/gin"
86
"os"
97
"path/filepath"
108

9+
"github.com/flipped-aurora/gin-vue-admin/server/core/internal"
10+
"github.com/flipped-aurora/gin-vue-admin/server/global"
1111
"github.com/fsnotify/fsnotify"
12+
"github.com/gin-gonic/gin"
1213
"github.com/spf13/viper"
13-
14-
"github.com/flipped-aurora/gin-vue-admin/server/global"
1514
)
1615

17-
// Viper //
18-
// 优先级: 命令行 > 环境变量 > 默认值
19-
// Author [SliverHorn](https://github.com/SliverHorn)
20-
func Viper(path ...string) *viper.Viper {
21-
var config string
22-
23-
if len(path) == 0 {
24-
flag.StringVar(&config, "c", "", "choose config file.")
25-
flag.Parse()
26-
if config == "" { // 判断命令行参数是否为空
27-
if configEnv := os.Getenv(internal.ConfigEnv); configEnv == "" { // 判断 internal.ConfigEnv 常量存储的环境变量是否为空
28-
switch gin.Mode() {
29-
case gin.DebugMode:
30-
config = internal.ConfigDefaultFile
31-
case gin.ReleaseMode:
32-
config = internal.ConfigReleaseFile
33-
case gin.TestMode:
34-
config = internal.ConfigTestFile
35-
}
36-
fmt.Printf("您正在使用gin模式的%s环境名称,config的路径为%s\n", gin.Mode(), config)
37-
} else { // internal.ConfigEnv 常量存储的环境变量不为空 将值赋值于config
38-
config = configEnv
39-
fmt.Printf("您正在使用%s环境变量,config的路径为%s\n", internal.ConfigEnv, config)
40-
}
41-
} else { // 命令行参数不为空 将值赋值于config
42-
fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%s\n", config)
43-
}
44-
} else { // 函数传递的可变参数的第一个值赋值于config
45-
config = path[0]
46-
fmt.Printf("您正在使用func Viper()传递的值,config的路径为%s\n", config)
47-
}
16+
// Viper 配置
17+
func Viper() *viper.Viper {
18+
config := getConfigPath()
4819

4920
v := viper.New()
5021
v.SetConfigFile(config)
5122
v.SetConfigType("yaml")
5223
err := v.ReadInConfig()
5324
if err != nil {
54-
panic(fmt.Errorf("Fatal error config file: %s \n", err))
25+
panic(fmt.Errorf("fatal error config file: %w", err))
5526
}
5627
v.WatchConfig()
5728

@@ -62,10 +33,44 @@ func Viper(path ...string) *viper.Viper {
6233
}
6334
})
6435
if err = v.Unmarshal(&global.GVA_CONFIG); err != nil {
65-
panic(err)
36+
panic(fmt.Errorf("fatal error unmarshal config: %w", err))
6637
}
6738

6839
// root 适配性 根据root位置去找到对应迁移位置,保证root路径有效
6940
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
7041
return v
7142
}
43+
44+
// getConfigPath 获取配置文件路径, 优先级: 命令行 > 环境变量 > 默认值
45+
func getConfigPath() (config string) {
46+
// `-c` flag parse
47+
flag.StringVar(&config, "c", "", "choose config file.")
48+
flag.Parse()
49+
if config != "" { // 命令行参数不为空 将值赋值于config
50+
fmt.Printf("您正在使用命令行的 '-c' 参数传递的值, config 的路径为 %s\n", config)
51+
return
52+
}
53+
if env := os.Getenv(internal.ConfigEnv); env != "" { // 判断环境变量 GVA_CONFIG
54+
config = env
55+
fmt.Printf("您正在使用 %s 环境变量, config 的路径为 %s\n", internal.ConfigEnv, config)
56+
return
57+
}
58+
59+
switch gin.Mode() { // 根据 gin 模式文件名
60+
case gin.DebugMode:
61+
config = internal.ConfigDebugFile
62+
case gin.ReleaseMode:
63+
config = internal.ConfigReleaseFile
64+
case gin.TestMode:
65+
config = internal.ConfigTestFile
66+
}
67+
fmt.Printf("您正在使用 gin 的 %s 模式运行, config 的路径为 %s\n", gin.Mode(), config)
68+
69+
_, err := os.Stat(config)
70+
if err != nil || os.IsNotExist(err) {
71+
config = internal.ConfigDefaultFile
72+
fmt.Printf("配置文件路径不存在, 使用默认配置文件路径: %s\n", config)
73+
}
74+
75+
return
76+
}

Diff for: server/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/glebarez/sqlite v1.11.0
1414
github.com/go-sql-driver/mysql v1.8.1
1515
github.com/goccy/go-json v0.10.4
16-
github.com/golang-jwt/jwt/v5 v5.2.1
16+
github.com/golang-jwt/jwt/v5 v5.2.2
1717
github.com/google/uuid v1.6.0
1818
github.com/gookit/color v1.5.4
1919
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.24.9+incompatible

Diff for: server/go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
169169
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
170170
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
171171
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
172-
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
173172
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
173+
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
174+
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
174175
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
175176
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
176177
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=

Diff for: server/initialize/router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Routers() *gin.Engine {
4646
// VUE_APP_BASE_API = /
4747
// VUE_APP_BASE_PATH = http://localhost
4848
// 然后执行打包命令 npm run build。在打开下面3行注释
49-
// Router.Static("/favicon.ico", "./dist/favicon.ico")
49+
// Router.StaticFile("/favicon.ico", "./dist/favicon.ico")
5050
// Router.Static("/assets", "./dist/assets") // dist里面的静态资源
5151
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
5252

Diff for: web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@vue/cli-plugin-vuex": "~5.0.8",
6464
"@vue/cli-service": "~5.0.8",
6565
"@vue/compiler-sfc": "^3.5.1",
66+
"autoprefixer": "^10.4.20",
6667
"babel-plugin-import": "^1.13.8",
6768
"chalk": "^5.3.0",
6869
"dotenv": "^16.4.5",

Diff for: web/src/view/systemTools/autoPkg/autoPkg.vue

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
callback(new Error('不能为中文'))
124124
} else if (/^\d+$/.test(value[0])) {
125125
callback(new Error('不能够以数字开头'))
126+
} else if (!/^[a-zA-Z0-9_]+$/.test(value)) {
127+
callback(new Error('只能包含英文字母、数字和下划线'))
126128
} else {
127129
callback()
128130
}

0 commit comments

Comments
 (0)