-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 1.06 KB
/
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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/MayankUjawane/gobank/controllers"
"github.com/MayankUjawane/gobank/db"
"github.com/MayankUjawane/gobank/token"
"github.com/MayankUjawane/gobank/util"
"github.com/joho/godotenv"
)
func main() {
// storing seed value as false, will pass true through command prompt whenever required to seed the value
seed := flag.Bool("seed", false, "seed teh db")
flag.Parse()
// loading env file
err := godotenv.Load("local.env")
if err != nil {
log.Fatalf("Some error occured in env file: %s", err)
}
// making connection with the database
store, err := db.NewPostgresStore()
if err != nil {
log.Fatalf("error while making connection with db: %s", err)
}
// creating required table in database
if err := store.Init(); err != nil {
log.Fatal(err)
}
// seed some accounts
if *seed {
fmt.Println("Seeding the database")
util.SeedAccounts(store)
}
tokenMaker := token.NewJWTMaker(os.Getenv("JWT_SECRET"))
server := controllers.NewAPIServer(":3000", store, tokenMaker)
server.SetupRouter(tokenMaker)
}