Browse Source

Update DB

Dima 6 months ago
parent
commit
030cc558d9
1 changed files with 13 additions and 0 deletions
  1. 13 0
      db/db.go

+ 13 - 0
db/db.go

@@ -3,6 +3,7 @@ package db
 import (
 	"context"
 	"database/sql"
+	"errors"
 	"fmt"
 	"strconv"
 )
@@ -14,6 +15,18 @@ type DB struct {
 }
 
 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 {
 		c.driver = defaultDriver
 	}