|
@@ -3,6 +3,7 @@ package db
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
"database/sql"
|
|
"database/sql"
|
|
|
|
+ "errors"
|
|
"fmt"
|
|
"fmt"
|
|
"strconv"
|
|
"strconv"
|
|
)
|
|
)
|
|
@@ -14,6 +15,18 @@ type DB struct {
|
|
}
|
|
}
|
|
|
|
|
|
func NewDB(c Config) (*DB, error) {
|
|
func NewDB(c Config) (*DB, error) {
|
|
|
|
+ if len(c.username) == 0 {
|
|
|
|
+ return nil, errors.New("empty username")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(c.password) == 0 {
|
|
|
|
+ return nil, errors.New("empty password")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(c.dbname) == 0 {
|
|
|
|
+ return nil, errors.New("empty database name")
|
|
|
|
+ }
|
|
|
|
+
|
|
if len(c.driver) == 0 {
|
|
if len(c.driver) == 0 {
|
|
c.driver = defaultDriver
|
|
c.driver = defaultDriver
|
|
}
|
|
}
|