fix: log info

This commit is contained in:
engigu
2024-04-29 21:10:17 +08:00
parent f4180dc920
commit a9d32c5094
3 changed files with 22 additions and 11 deletions
+9 -8
View File
@@ -43,7 +43,6 @@ func printOptionValue() {
func loadConfigFromEnv() {
AppSetting.JwtSecret = getOptionEnvValue("JWT_SECRET", "message-nest")
AppSetting.LogLevel = getOptionEnvValue("LOG_LEVEL", "INFO")
AppSetting.InitData = getOptionEnvValue("INIT_DATA", "")
ServerSetting.RunMode = getOptionEnvValue("RUN_MODE", "release")
ServerSetting.HttpPort = 8000
@@ -52,13 +51,15 @@ func loadConfigFromEnv() {
DatabaseSetting.Type = getOptionEnvValue("DB_TYPE", "sqlite")
DatabaseSetting.Host = getMustEnvValue("MYSQL_HOST")
DatabaseSetting.Port = com.StrTo(getMustEnvValue("MYSQL_PORT")).MustInt()
DatabaseSetting.User = getMustEnvValue("MYSQL_USER")
DatabaseSetting.Password = getMustEnvValue("MYSQL_PASSWORD")
DatabaseSetting.Name = getMustEnvValue("MYSQL_DB")
DatabaseSetting.TablePrefix = getMustEnvValue("MYSQL_TABLE_PREFIX")
DatabaseSetting.SqlDebug = getOptionEnvValue("SQL_DEBUG", "disable")
if DatabaseSetting.Type == "mysql" {
DatabaseSetting.Host = getMustEnvValue("MYSQL_HOST")
DatabaseSetting.Port = com.StrTo(getMustEnvValue("MYSQL_PORT")).MustInt()
DatabaseSetting.User = getMustEnvValue("MYSQL_USER")
DatabaseSetting.Password = getMustEnvValue("MYSQL_PASSWORD")
DatabaseSetting.Name = getMustEnvValue("MYSQL_DB")
}
DatabaseSetting.TablePrefix = getOptionEnvValue("MYSQL_TABLE_PREFIX", "message_")
DatabaseSetting.SqlDebug = getOptionEnvValue("SQL_DEBUG", "disable")
printOptionValue()
}
+12 -2
View File
@@ -49,10 +49,22 @@ func fileExists(filePath string) bool {
return !os.IsNotExist(err)
}
func createConfFolder() {
// 检查目录是否存在
dir := "conf/"
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0755)
if err != nil {
return
}
}
}
// Setup initialize the configuration instance
func Setup() {
var err error
intPath := "conf/app.ini"
createConfFolder()
if fileExists(intPath) {
log.Printf("[message-nest] start server from %s.", intPath)
@@ -72,8 +84,6 @@ func Setup() {
ServerSetting.ReadTimeout = ServerSetting.ReadTimeout * time.Second
ServerSetting.WriteTimeout = ServerSetting.WriteTimeout * time.Second
log.Printf("[message-nest] DB type: %s", DatabaseSetting.Type)
}
// mapTo map section