package model import ( "fmt" "log" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" ) var x *sqlx.DB // NewDB - connect to database func NewDB() (*sqlx.DB, error) { var err error connStr := fmt.Sprintf("user=%s host=%s sslmode=disable dbname=%s port=%d", "postgres", "localhost", "mtfosbot", 5432) x, err = sqlx.Connect("postgres", connStr) if err != nil { log.Fatal(err) } x.SetMaxIdleConns(10) x.SetMaxOpenConns(200) err = x.Ping() if err != nil { log.Fatal(err) } return x, err }