init module

This commit is contained in:
Nam Huynh 2021-08-09 10:30:00 +07:00
parent ccb7843d48
commit f4da943b5d
1 changed files with 3 additions and 1 deletions

View File

@ -15,13 +15,15 @@ var (
sqlxClient *sqlx.DB sqlxClient *sqlx.DB
) )
// Connect to postgres database // Connect to postgresql database
func Connect(host, user, password, dbname, port, sslmode string) error { func Connect(host, user, password, dbname, port, sslmode string) error {
// Connect string // Connect string
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s TimeZone=UTC", dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s TimeZone=UTC",
host, user, password, dbname, port, sslmode, host, user, password, dbname, port, sslmode,
) )
// TODO: write case for SSL mode
db, err := sqlx.Connect("postgres", dsn) db, err := sqlx.Connect("postgres", dsn)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)