-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
95 lines (78 loc) · 1.71 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"embed"
"fmt"
"os"
"github.com/d2jvkpn/go-backend/bin"
"github.com/d2jvkpn/gotk"
"github.com/spf13/viper"
)
var (
//go:embed project.yaml
_Project []byte
//go:embed deploy/compose.template.yaml
_Compose []byte
//go:embed migrations/*.sql
_Migrations embed.FS
)
func main() {
var (
err error
project *viper.Viper
command *gotk.Command
)
defer func() {
if err != nil {
fmt.Fprintf(os.Stderr, "Exit: %s\n", err)
os.Exit(1)
}
}()
if project, err = gotk.ProjectFromBytes(_Project); err != nil {
err = fmt.Errorf("Failed to load project: %w", err)
return
}
if project.GetString("app_name") == "" || project.GetString("app_version") == "" {
err = fmt.Errorf("Neither app_name nor app_version is set in project.yaml")
return
}
command = gotk.NewCommand(project.GetString("meta.app_name"), project)
command.AddCmd(
"config",
"show configuration(api, crons, swagger, deployment)",
func(args []string) {
errMsg := "Subcommand is required: api | crons | swagger | deployment\n"
if len(args) == 0 {
fmt.Fprintf(os.Stderr, errMsg)
os.Exit(1)
}
switch args[0] {
case "api", "crons", "swagger":
fmt.Printf("%s\n", project.GetString(args[0]+"_config"))
case "compose":
fmt.Printf("%s\n", _Compose)
default:
fmt.Fprintf(os.Stderr, errMsg)
os.Exit(1)
}
},
)
command.AddCmd(
"api", "api service",
func(args []string) {
bin.RunApi(project, args, _Migrations)
},
)
command.AddCmd(
"crons", "cron deamon",
func(args []string) {
bin.RunCrons(project, args)
},
)
command.AddCmd(
"swagger", "swagger service",
func(args []string) {
bin.RunBin("swagger", args)
},
)
command.Execute(os.Args[1:])
}