-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (36 loc) · 792 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
package main
import (
"flag"
"fmt"
"log"
"github.com/im-karina/basics/cfg"
"github.com/im-karina/basics/db"
"github.com/im-karina/basics/srv"
)
func main() {
flag.Parse()
cfg.Load()
taskFns = make(map[string]func(s string) error)
taskFns["db:drop"] = db.Drop
taskFns["db:migrate"] = db.Migrate
taskFns["db:rollback"] = db.Rollback
taskFns["db:schema:dump"] = db.DumpSchema
taskFns["db:wal_cleanup"] = db.WalCleanup
taskFns["serve"] = srv.Serve
log.Println("connecting to database")
db.MustConnectOnce()
defer db.Db.Close()
for _, cmd := range flag.Args() {
DoTask(cmd)
}
}
var taskFns map[string]func(s string) error
func DoTask(s string) {
fn, ok := taskFns[s]
if !ok {
log.Fatalln("unknown task:", s)
}
fmt.Println(">", s)
fn(s)
fmt.Println("done")
}