|
@@ -41,17 +41,23 @@ func NewDB(c Config) (*DB, error) {
|
|
|
c.port = defaultPort
|
|
|
}
|
|
|
|
|
|
- if len(c.sslMode) == 0 {
|
|
|
- c.sslMode = defaultSslMode
|
|
|
+ var source string
|
|
|
+
|
|
|
+ switch c.driver {
|
|
|
+ case "mysql":
|
|
|
+ source = c.username +
|
|
|
+ ":" + c.password +
|
|
|
+ "@tcp(" + c.host + ":" + strconv.Itoa(int(c.port)) + ")/" +
|
|
|
+ c.dbname +
|
|
|
+ "?parseTime=true"
|
|
|
+ case "postgres":
|
|
|
+ source = "user=" + c.username +
|
|
|
+ " password=" + c.password +
|
|
|
+ " dbname=/" + c.dbname +
|
|
|
+ " host=" + c.host +
|
|
|
+ " port=" + strconv.Itoa(int(c.port))
|
|
|
}
|
|
|
|
|
|
- source := "user=" + c.username +
|
|
|
- " password=" + c.password +
|
|
|
- " dbname=" + c.dbname +
|
|
|
- " host=" + c.host +
|
|
|
- " port=" + strconv.Itoa(int(c.port)) +
|
|
|
- " sslmode=" + c.sslMode
|
|
|
-
|
|
|
sqlConn, err := sql.Open(c.driver, source)
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("open DB connection error: %w", err)
|