-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (39 loc) · 944 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 (
"errors"
"fmt"
"os"
"github.com/joesantosio/example-order-book/config"
"github.com/joesantosio/example-order-book/entity"
"github.com/joesantosio/example-order-book/infrastructure/sqlite"
"github.com/joesantosio/example-order-book/interfaces/cli"
)
func initRepos(dbPath string) (entity.Repositories, error) {
if dbPath == "" {
return nil, errors.New("DB_PATH not provided")
}
db, err := sqlite.Connect(dbPath)
if err != nil {
return nil, errors.New(fmt.Sprintf("error initializing db: %v", err))
}
repos, err := sqlite.InitRepos(db)
if err != nil {
return nil, errors.New(fmt.Sprintf("error initializing repos: %v", err))
}
return repos, nil
}
func main() {
config, err := config.Get(os.Getenv)
if err != nil {
panic(err)
}
repos, err := initRepos(config.DBPath)
if err != nil {
panic(err)
}
defer repos.Close()
err = cli.Init(os.Args, repos)
if err != nil {
panic(err)
}
}