Skip to content

Instantly share code, notes, and snippets.

@darmawan01
Last active May 16, 2020 14:41
Show Gist options
  • Save darmawan01/ab7d9465c7624f2361d5b97087a55c72 to your computer and use it in GitHub Desktop.
Save darmawan01/ab7d9465c7624f2361d5b97087a55c72 to your computer and use it in GitHub Desktop.
Setup postgres For Go
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