Last active
May 16, 2020 14:41
-
-
Save darmawan01/ab7d9465c7624f2361d5b97087a55c72 to your computer and use it in GitHub Desktop.
Setup postgres For Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package db | |
import "github.com/jackc/pgx" | |
// InitPostgres func | |
func InitPostgres() (dbConnPool *pgx.ConnPool) { | |
conf := getConfig() | |
var err error | |
pgxConf := &pgx.ConnConfig{ | |
Port: uint16(conf.Port), | |
Host: conf.Host, | |
User: conf.User, | |
Password: conf.Password, | |
Database: conf.DbName, | |
} | |
if dbConnPool, err = pgx.NewConnPool( | |
pgx.ConnPoolConfig{ | |
ConnConfig: *pgxConf, | |
MaxConnections: 5, | |
}, | |
); err != nil { | |
panic(err) | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment