Skip to content

Commit

Permalink
chore: read db username from env
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Feb 26, 2024
1 parent 991111d commit bfa9fb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ type App struct {
}

func NewApp(cfg *config.Config) *App {
username := cfg.DBConfig.Username
username := viper.GetString(config.FlagConfigDbUsername)
if username == "" {
username = os.Getenv(config.ConfigDBUserName)
if username == "" {
username = cfg.DBConfig.Username
}
}
password := viper.GetString(config.FlagConfigDbPass)
if password == "" {
password = os.Getenv(config.ConfigDBPass)
Expand Down
8 changes: 5 additions & 3 deletions config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
FlagConfigPrivateKey = "private-key"
FlagConfigBlsPrivateKey = "bls-private-key"
FlagConfigDbPass = "db-pass"
FlagConfigDbUsername = "db-username"

DBDialectMysql = "mysql"
DBDialectSqlite3 = "sqlite3"
Expand All @@ -17,7 +18,8 @@ const (
KeyTypeLocalPrivateKey = "local_private_key"
KeyTypeAWSPrivateKey = "aws_private_key"

ConfigType = "CONFIG_TYPE"
ConfigFilePath = "CONFIG_FILE_PATH"
ConfigDBPass = "DB_PASS"
ConfigType = "CONFIG_TYPE"
ConfigFilePath = "CONFIG_FILE_PATH"
ConfigDBPass = "DB_PASSWORD"
ConfigDBUserName = "DB_USERNAME"
)
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func initFlags() {
flag.String(config.FlagConfigPrivateKey, "", "relayer private key")
flag.String(config.FlagConfigBlsPrivateKey, "", "relayer bls private key")
flag.String(config.FlagConfigDbPass, "", "relayer db password")
flag.String(config.FlagConfigDbUsername, "", "relayer db username")

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
Expand Down

0 comments on commit bfa9fb3

Please sign in to comment.