-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (39 loc) · 992 Bytes
/
main.go
File metadata and controls
50 lines (39 loc) · 992 Bytes
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
package main
import (
"database/sql"
"fmt"
"log"
"os"
"github.com/REZ-OAN/simplebank/utils"
db "github.com/REZ-OAN/simplebank/database/sqlc"
"github.com/REZ-OAN/simplebank/api"
_ "github.com/lib/pq"
)
func main() {
path := os.Getenv("path")
name := os.Getenv("name")
ext := os.Getenv("ext")
if path == "" || name == "" || ext == "" {
log.Fatalln("All arguments should be given!!!")
return
}
config, err := utils.LoadConfig(path, name, ext)
if err != nil {
log.Fatalf("cannot get configs: %v", err)
}
conn, err := sql.Open(config.DB_DRIVER, config.DB_SOURCE)
if err != nil {
log.Fatal("cannot connect to the db: ", err)
}
store := db.NewStore(conn)
server, err := api.NewServer(store, config)
if err != nil {
log.Fatal("cannot create server ", err)
return
}
SERVER_URL := fmt.Sprintf("%s:%s", config.SERVER_ADDRESS, config.SERVER_PORT)
err = server.Start(SERVER_URL)
if err != nil {
log.Fatalf("Cannont Connect to the server : %v", err)
}
}