forked from anthdm/gobank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (37 loc) · 750 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
package main
import (
"flag"
"fmt"
"log"
)
func seedAccount(store Storage, fname, lname, pw string) *Account {
acc, err := NewAccount(fname, lname, pw)
if err != nil {
log.Fatal(err)
}
if err := store.CreateAccount(acc); err != nil {
log.Fatal(err)
}
fmt.Println("new account => ", acc.Number)
return acc
}
func seedAccounts(s Storage) {
seedAccount(s, "anthony", "GG", "hunter88888")
}
func main() {
seed := flag.Bool("seed", false, "seed the db")
flag.Parse()
store, err := NewPostgresStore()
if err != nil {
log.Fatal(err)
}
if err := store.Init(); err != nil {
log.Fatal(err)
}
if *seed {
fmt.Println("seeding the database")
seedAccounts(store)
}
server := NewAPIServer(":3000", store)
server.Run()
}