-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (41 loc) · 981 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
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
"github.com/rammyblog/go-product-subscriptions/config"
"github.com/rammyblog/go-product-subscriptions/database"
"github.com/rammyblog/go-product-subscriptions/router"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
seed := flag.Bool("seed", false, "seed the db")
flag.Parse()
paystackClient := Paystack()
db, err := database.Init(seed)
if err != nil {
log.Fatal("Could not connect to db")
panic(err)
}
fmt.Println("db conected", db.Name())
config.GlobalConfig = &config.AppConfig{
DB: db,
PaystackClient: paystackClient,
}
if seed != nil && *seed {
database.Seed(db)
}
port := fmt.Sprintf(":%v", os.Getenv("PORT"))
handler := router.Init()
server := &http.Server{
Addr: port,
Handler: handler,
}
log.Printf("[info] start http server listening %s", port)
server.ListenAndServe()
}