Skip to content

Commit

Permalink
Merge pull request #23 from TRON-US/rm-debug-zap-log
Browse files Browse the repository at this point in the history
Rm debug zap log
  • Loading branch information
Eric Chen authored Sep 19, 2020
2 parents fe536f5 + 349d439 commit 4d27504
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions env/db/pg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"os"
"strconv"
"time"

Expand Down Expand Up @@ -34,6 +35,9 @@ var (

func init() {

if os.Getenv(env.EnvNamePrefix) == "" && os.Getenv(env.EnvNamePrefixEnv) == "" {
return
}
if _, duW := env.GetEnv("DB_URL"); duW != "" {
DBWriteURL = duW
// if slave url passed, use it as read default
Expand All @@ -50,68 +54,68 @@ func init() {
writeUserName = _un
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbWUnKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbWUnKey))
}

envDbWPwdKey, _pwd := env.GetEnv("DB_WRITE_PASSWORD")
if _pwd != "" {
writePwd = _pwd
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbWPwdKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbWPwdKey))
}

envDbWHost, _host := env.GetEnv("DB_WRITE_HOST")
if _host != "" {
writeHost = _host
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbWHost))
log.Warn(constant.EmptyVarError, zap.String("env", envDbWHost))
}

envDbWNameKey, _dbName := env.GetEnv("DB_WRITE_NAME")
if _dbName != "" {
writeDbName = _dbName
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbWNameKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbWNameKey))
}
envDbRUnKey, un := env.GetEnv("DB_READ_USERNAME")
if un != "" {
readUserName = un
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbRUnKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbRUnKey))
}

envDbRPwdKey, pwd := env.GetEnv("DB_READ_PASSWORD")
if pwd != "" {
readPwd = pwd
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbRPwdKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbRPwdKey))
}

envDbRHostKey, host := env.GetEnv("DB_READ_HOST")
if host != "" {
readHost = host
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbRHostKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbRHostKey))
}

envDbRNameKey, dbName := env.GetEnv("DB_READ_NAME")
if dbName != "" {
readDbName = dbName
} else {
hasError = true
log.Debug(constant.EmptyVarError, zap.String("env", envDbRNameKey))
log.Warn(constant.EmptyVarError, zap.String("env", envDbRNameKey))
}

DBWriteURL = "postgresql://" + writeUserName + ":" + writePwd + "@" + writeHost + ":5432/" + writeDbName
DBReadURL = "postgresql://" + readUserName + ":" + readPwd + "@" + readHost + ":5432/" + readDbName
if hasError {
log.Debug("error to get DBWriteUrl or DBReadURL from env", zap.String("WriteUrl", DBWriteURL), zap.String("ReadUrl", DBReadURL))
log.Warn("error to get DBWriteUrl or DBReadURL from env", zap.String("WriteUrl", DBWriteURL), zap.String("ReadUrl", DBReadURL))
}
}

Expand All @@ -120,14 +124,14 @@ func init() {
}
if envKey, dbst := env.GetEnv("DB_STMT_TIMEOUT"); dbst != "" {
if toInt, err := strconv.ParseInt(dbst, 10, 64); err != nil {
log.Debug(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
log.Warn(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
} else {
DBStmtTimeout = time.Duration(toInt) * time.Second
}
}
if envKey, dbnc := env.GetEnv("DB_NUM_CONNS"); dbnc != "" {
if toInt, err := strconv.ParseInt(dbnc, 10, 64); err != nil {
log.Debug(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
log.Warn(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
} else {
DBNumConns = int(toInt)
}
Expand Down

0 comments on commit 4d27504

Please sign in to comment.