Добавлен основные классы для сервиса авторизаци
This commit is contained in:
35
internal/repository/postgres.go
Normal file
35
internal/repository/postgres.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
const (
|
||||
usersTable = "users"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Host string
|
||||
Port string
|
||||
Username string
|
||||
Password string
|
||||
DBName string
|
||||
SSLMode string
|
||||
}
|
||||
|
||||
func NewPostgresDB(cfg Config) (*sql.DB, error) {
|
||||
db, err := sql.Open("postgres",
|
||||
fmt.Sprintf("user=%s password=%s host=%s dbname=%s sslmode=%s",
|
||||
cfg.Username, cfg.Password, cfg.Host, cfg.DBName, cfg.SSLMode))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = db.Ping()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
Reference in New Issue
Block a user