-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (48 loc) · 1.1 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
48
49
50
51
52
53
54
55
package main
import (
"database/sql"
"log"
"os"
"github.com/chichigami/blog-aggregator/internal/config"
"github.com/chichigami/blog-aggregator/internal/database"
_ "github.com/lib/pq"
)
func main() {
configFile, err := config.GetConfigFilePath()
if err != nil {
log.Fatalf("error reading config: %v", err)
}
cfg := config.ReadAndParse(configFile)
dbURL := cfg.DbURL
db, db_err := sql.Open("postgres", dbURL)
if db_err != nil {
log.Fatal(err)
}
dbQueries := database.New(db)
userCfg := state{
cfg: &cfg,
db: dbQueries,
}
cmds := commands{
handlers: make(map[string]func(*state, command) error),
}
cmds.register("login", handlerLogin)
cmds.register("register", handlerRegister)
cmds.register("reset", handlerReset)
cmds.register("users", handlerUsers)
cmds.register("agg", handlerAgg)
cmds.register("addfeed", handlerAddFeed)
cmds.register("feeds", handlerFeeds)
input := os.Args
if len(input) < 2 {
log.Fatal("not enough arguments")
}
commandInput := command{
name: input[1],
args: input[2:],
}
err = cmds.run(&userCfg, commandInput)
if err != nil {
log.Fatal(err)
}
}