-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
125 lines (120 loc) · 2.81 KB
/
main.go
File metadata and controls
125 lines (120 loc) · 2.81 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"os"
"github.com/joho/godotenv"
"github.com/urfave/cli"
"github.com/earaujoassis/space/internal"
"github.com/earaujoassis/space/internal/config"
"github.com/earaujoassis/space/internal/logs"
"github.com/earaujoassis/space/internal/tasks"
"github.com/earaujoassis/space/internal/utils"
)
func main() {
defer utils.RecoverHandler()
err := godotenv.Load()
if err == nil {
logs.Propagate(logs.LevelInfo, "Application has found a .env file")
}
cfg, err := config.Load()
if err != nil {
logs.Propagatef(logs.LevelPanic, "Could not load configuration: %s\n", err)
}
logs.Setup(logs.Options{
Environment: cfg.Environment,
Release: cfg.Release(),
SentryUrl: cfg.SentryUrl,
})
app := cli.NewApp()
app.Name = "space"
app.Version = internal.Version
app.Usage = "A user management microservice; OAuth 2 provider"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
{
Name: "database",
Aliases: []string{"db"},
Usage: "Run actions against the database",
Subcommands: []cli.Command{
{
Name: "migrate",
Usage: "Apply migrations to the database upward",
Flags: []cli.Flag{
cli.StringFlag{
Name: "path",
Value: "./configs/migrations",
Usage: "Migrations folder relative path",
},
},
Action: func(c *cli.Context) error {
tasks.RunMigrations(cfg, c.String("path"))
return nil
},
},
{
Name: "rollback",
Usage: "Apply migrations to the database downward",
Flags: []cli.Flag{
cli.StringFlag{
Name: "path",
Value: "./configs/migrations",
Usage: "Migrations folder relative path",
},
},
Action: func(c *cli.Context) error {
tasks.RollbackMigrations(cfg, c.String("path"))
return nil
},
},
},
},
{
Name: "serve",
Usage: "Serve the application server",
Action: func(c *cli.Context) error {
tasks.Server(cfg)
return nil
},
},
{
Name: "launch",
Usage: "Apply migrations and serve the application server",
Flags: []cli.Flag{
cli.StringFlag{
Name: "path",
Value: "./configs/migrations",
Usage: "Migrations folder relative path",
},
},
Action: func(c *cli.Context) error {
tasks.RunMigrations(cfg, c.String("path"))
tasks.Server(cfg)
return nil
},
},
{
Name: "workers",
Usage: "Start the workers server/service",
Action: func(c *cli.Context) error {
tasks.Workers(cfg)
return nil
},
},
{
Name: "scheduler",
Usage: "Start the scheduler service",
Action: func(c *cli.Context) error {
tasks.Scheduler(cfg)
return nil
},
},
{
Name: "feature",
Usage: "Toggle feature flags ON/OFF",
Action: func(c *cli.Context) error {
tasks.ToggleFeature(cfg)
return nil
},
},
}
app.Run(os.Args)
}