-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 983 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
package main
import (
"flag"
"log"
"strings"
"github.com/xybor/xychat/helpers"
"github.com/xybor/xychat/models"
"github.com/xybor/xychat/routers"
"github.com/xybor/xychat/seeds"
servicev1 "github.com/xybor/xychat/services/v1"
)
func main() {
reset := flag.Bool("reset", false, "Drop all tables before auto-migrating")
admin := flag.String("admin", "", "Create an admin user with format username:password")
run := flag.Bool("run", false, "Run the server")
dotenv := flag.Bool("dotenv", false, "Load environment variables from .env file")
flag.Parse()
if *dotenv {
helpers.LoadEnv()
}
models.InitializeDB()
models.CreateTables(*reset)
if *admin != "" {
credentials := strings.Split(*admin, ":")
if len(credentials) != 2 {
log.Fatal("Invalid admin credentials")
}
seeds.SeedAdminUser(credentials[0], credentials[1])
}
if *run {
servicev1.InitializeMatchQueue()
router := routers.Route()
router.Run(":" + helpers.MustReadEnv("port"))
}
}