diff --git a/admin/.env.development b/admin/.env.development new file mode 100644 index 0000000..d9100c4 --- /dev/null +++ b/admin/.env.development @@ -0,0 +1,2 @@ +# 请求域名 +VITE_APP_BASE_URL='http://127.0.0.1:8080' diff --git a/admin/.gitignore b/admin/.gitignore index 81d06c9..82c1a87 100644 --- a/admin/.gitignore +++ b/admin/.gitignore @@ -32,6 +32,6 @@ components.d.ts *.sw? # .env -.env.development +# .env.development .env.production test.html diff --git a/server/.env.example b/server/.env.example index c4711f1..c61e6a8 100644 --- a/server/.env.example +++ b/server/.env.example @@ -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/' diff --git a/server/.env.yaml.example b/server/.env.yaml.example new file mode 100644 index 0000000..8b13c7a --- /dev/null +++ b/server/.env.yaml.example @@ -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/' diff --git a/server/config/config.go b/server/config/config.go index ab50fde..63e3542 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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 -// } diff --git a/server/config/db.go b/server/config/db.go index a3666d9..0f9becb 100644 --- a/server/config/db.go +++ b/server/config/db.go @@ -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,