File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -19,9 +19,10 @@ type Config struct {
19
19
}
20
20
21
21
type DBConfig struct {
22
- DSN string `default:"" flag:"dsn" usage:"Database DSN"`
23
- User string `default:"" flag:"user"`
24
- Pass string `default:"" flag:"pass"`
22
+ DSN string `default:"" flag:"dsn" usage:"Database DSN"`
23
+ User string
24
+ Pass string
25
+ DBName string
25
26
}
26
27
27
28
func OpenDB () (* sql.DB , error ) {
@@ -91,8 +92,12 @@ func createConnector(configFile string) CreateConnectorFunc {
91
92
// log.Printf("db cfg: %+v", cfg)
92
93
93
94
dsn := cfg .MySQL .DSN
95
+
94
96
if len (dsn ) == 0 {
95
- return nil , fmt .Errorf ("--database.dsn flag or DATABASE_DSN environment variable required" )
97
+ dsn = os .Getenv ("DATABASE_DSN" )
98
+ if len (dsn ) == 0 {
99
+ return nil , fmt .Errorf ("dsn config in database.yaml or DATABASE_DSN environment variable required" )
100
+ }
96
101
}
97
102
98
103
dbcfg , err := mysql .ParseDSN (dsn )
@@ -108,6 +113,10 @@ func createConnector(configFile string) CreateConnectorFunc {
108
113
dbcfg .Passwd = pass
109
114
}
110
115
116
+ if name := cfg .MySQL .DBName ; len (name ) > 0 {
117
+ dbcfg .DBName = name
118
+ }
119
+
111
120
return mysql .NewConnector (dbcfg )
112
121
}
113
122
}
You can’t perform that action at this time.
0 commit comments