-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
39 lines (33 loc) · 894 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"database/sql"
_ "github.com/lib/pq"
"github.com/nasermirzaei89/github-visit-counter/app"
"github.com/nasermirzaei89/github-visit-counter/repositories/postgres"
"github.com/pkg/errors"
"net/http"
"os"
)
func main() {
//db, err := bolt.Open("db.bolt", 0666, nil)
//if err != nil {
// panic(errors.Wrap(err, "error on open db"))
//}
//defer func() { _ = db.Close() }()
//
//repo := boltdb.NewRepository(db)
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
if err != nil {
panic(errors.Wrap(err, "error on open postgres db"))
}
defer func() { _ = db.Close() }()
err = db.Ping()
if err != nil {
panic(errors.Wrap(err, "error on ping postgres db"))
}
repo := postgres.NewRepository(db)
err = http.ListenAndServe(":"+os.Getenv("PORT"), app.NewHandler(repo))
if err != nil {
panic(errors.Wrap(err, "error on listen and serve"))
}
}