配置示例文件

This commit is contained in:
xh
2025-07-27 15:39:03 +08:00
parent 2f2b4a5ca9
commit bab7ea61ec
6 changed files with 32 additions and 32 deletions

2
admin/.env.development Normal file
View File

@@ -0,0 +1,2 @@
# 请求域名
VITE_APP_BASE_URL='http://127.0.0.1:8080'

2
admin/.gitignore vendored
View File

@@ -32,6 +32,6 @@ components.d.ts
*.sw?
# .env
.env.development
# .env.development
.env.production
test.html

View File

@@ -1,14 +1,15 @@
# 配置项参考config\config.go
# 具体配置项参考config\config.go的config结构体
# APP.GIN_MODE='debug'
#GIN_MODE='release'
# 项目端口
SERVER_PORT=8001
APP.PORT=8001
# 数据库
DATABASE_URL='root:root@tcp(localhost:3306)/x_admin?charset=utf8mb4&parseTime=True&loc=Local'
DB.DSN='root:root@tcp(localhost:3306)/x_admin?charset=utf8mb4&parseTime=True&loc=Local'
#Redis
REDIS_URL='redis://:passwd@localhost:6379'
REDIS.URL='redis://localhost:6379'
# 上传文件目录
UPLOAD_DIRECTORY='/www/wwwroot/x_admin_go/public/uploads/'
FILE.UPLOAD_DIRECTORY='/www/wwwroot/x_admin_go/public/uploads/'

20
server/.env.yaml.example Normal file
View File

@@ -0,0 +1,20 @@
# 具体配置项参考config\config.go的config结构体
# APP:
# GIN_MODE: 'debug'
# 项目端口
APP:
PORT: 8080
# 数据库
DB:
DSN: 'root:root@tcp(localhost:3306)/x_admin?charset=utf8mb4&parseTime=True&loc=Local'
#Redis
REDIS:
URL: 'redis://localhost:6379'
# 上传文件目录
FILE:
UPLOAD_DIRECTORY: '/www/wwwroot/x_admin_go/public/uploads/'

View File

@@ -29,6 +29,7 @@ func loadConfig(config config) config {
if envFilePath == "" {
envFilePath = ".env"
}
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.SetConfigFile(envFilePath)
viper.AutomaticEnv()
@@ -45,32 +46,8 @@ func loadConfig(config config) config {
}
func init() {
// fmt.Println(Config)
fmt.Println("AppConfig:", AppConfig)
fmt.Println("DBConfig:", DBConfig)
fmt.Println("RedisConfig:", RedisConfig)
fmt.Println("FileConfig:", FileConfig)
}
// loadConfig 加载配置
// func loadConfig(envPath string) envConfig {
// var cfgPath string
// flag.StringVar(&cfgPath, "c", "", "config file envPath.")
// flag.Parse()
// if cfgPath == "" {
// viper.AddConfigPath(envPath)
// viper.SetConfigFile(".env")
// } else {
// viper.SetConfigFile(cfgPath)
// }
// viper.AutomaticEnv()
// err := viper.ReadInConfig()
// if err != nil {
// log.Fatal("loadConfig ReadInConfig err:", err)
// }
// err = viper.Unmarshal(&config)
// if err != nil {
// log.Fatal("loadConfig Unmarshal err:", err)
// }
// return config
// }

View File

@@ -16,7 +16,7 @@ type dbConfig struct {
var DBConfig = dbConfig{
Type: "mysql",
Dsn: "root:123456@tcp(127.0.0.1:3306)/x_admin?charset=utf8mb4&parseTime=True&loc=Local",
Dsn: "", //root:123456@tcp(127.0.0.1:3306)/x_admin?charset=utf8mb4&parseTime=True&loc=Local
MaxOpenConns: 100,
MaxIdleConns: 10,
ConnMaxLifetimeSeconds: 60 * 60 * 24,