Skip to content

Commit

Permalink
Use a debug instance of the db if DEBUG env var is set
Browse files Browse the repository at this point in the history
Signed-off-by: ATechnoHazard <[email protected]>
  • Loading branch information
SphericalKat committed Dec 2, 2019
1 parent 01ee807 commit 7cbb02a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 6 additions & 4 deletions go_bot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ type Config struct {
BotName string
ApiKey string
OwnerName string
OwnerId int
SudoUsers []string
LoadPlugins []string
SqlUri string
RedisAddress string
RedisPassword string
OwnerId int
SudoUsers []string
LoadPlugins []string
DebugMode bool
Heroku bool
}

Expand Down Expand Up @@ -91,8 +92,9 @@ func init() {
returnConfig.RedisPassword = ""
}

_, returnConfig.DebugMode = os.LookupEnv("DEBUG")

_, returnConfig.Heroku = os.LookupEnv("HEROKU")

BotConfig = returnConfig

}
8 changes: 7 additions & 1 deletion go_bot/modules/sql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func init() {

db, err := gorm.Open("postgres", conn)
error_handling.FatalError(err)
SESSION = db.Debug()

if go_bot.BotConfig.DebugMode {
SESSION = db.Debug()
} else {
SESSION = db
}


if go_bot.BotConfig.Heroku {
db.DB().SetMaxOpenConns(20)
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ DATABASE_URI=
REDIS_ADDRESS =
REDIS_PASSWORD =
SUDO_USERS=
DEBUG=

0 comments on commit 7cbb02a

Please sign in to comment.