-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
72 lines (65 loc) · 1.3 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"go-pangu/args"
"go-pangu/db"
"go-pangu/models"
"go-pangu/redis"
"go-pangu/routers"
"log"
"os"
"sync"
"syscall"
"time"
"github.com/judwhite/go-svc/svc"
)
type program struct {
wg sync.WaitGroup
quit chan struct{}
}
func (p *program) Init(env svc.Environment) error {
redis.ConnectRedis()
// influx.ConnectInflux()
return nil
}
func (p *program) Start() error {
args.ParseCmd()
switch args.Cmd.DB {
case "create":
fmt.Println("creating database")
db.Create()
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
case "migrate":
fmt.Println("migrating tables")
db.Migrate(args.Cmd.GIN_ENV, &models.User{})
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
case "seed":
case "drop":
fmt.Println("droping database")
if args.Cmd.TABLE != "" {
db.Open("")
db.DB.Migrator().DropTable(args.Cmd.TABLE)
} else {
db.Drop()
}
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
case "createInflux":
// influx.Init()
default:
fmt.Println("server starting...")
db.Open("")
routers.InitRouter(os.Interrupt)
}
return nil
}
func (p *program) Stop() error {
fmt.Println("\nserver stoping")
time.Sleep(time.Duration(1) * time.Second)
return nil
}
func main() {
prg := &program{}
if err := svc.Run(prg, os.Interrupt); err != nil {
log.Fatal(err)
}
}