-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.go
49 lines (39 loc) · 888 Bytes
/
server.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
package main
import (
"flag"
"github.com/jinzhu/gorm"
"github.com/charlesfan/go-api/grpc"
"github.com/charlesfan/go-api/repository"
"github.com/charlesfan/go-api/repository/sqlite"
"github.com/charlesfan/go-api/route"
"github.com/charlesfan/go-api/service/rsi"
)
var (
d string
h string
m bool
)
func main() {
flag.StringVar(&d, "db", "sqlite", "db type")
flag.StringVar(&h, "host", "", "the host of db")
flag.BoolVar(&m, "migrate", false, "do db migrate")
flag.Parse()
// DB init
database := newDatabase(d, h, m)
defer database.Close()
// rsi.Services init
rsi.Init(database)
// Rest api init
router := route.Init()
go router.Run(":8080")
// gRPC
grpc.Run(":50051")
}
func newDatabase(s, host string, m bool) *repository.Database {
var db *gorm.DB
switch s {
case "sqlite":
db, _ = sqlite.NewSqlite(host, m)
}
return repository.NewDatabase(db)
}