-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
161 lines (138 loc) · 4.13 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"fmt"
"os"
"github.com/reivaj05/micro-gen/generator"
"github.com/reivaj05/GoCLI"
"github.com/reivaj05/GoConfig"
"github.com/reivaj05/GoLogger"
)
const appName = "micro-gen"
func main() {
setup()
startApp()
}
func setup() {
startConfig()
startLogger()
}
func startConfig() {
if err := GoConfig.Init(createConfigOptions()); err != nil {
finishExecution("Error while starting config", map[string]interface{}{
"error": err.Error(),
})
}
}
func createConfigOptions() *GoConfig.ConfigOptions {
return &GoConfig.ConfigOptions{
ConfigType: "json",
ConfigFile: "config",
ConfigPath: fmt.Sprintf("%s/src/github.com/reivaj05/micro-gen/", os.Getenv("GOPATH")),
}
}
func startLogger() {
if err := GoLogger.Init(createLoggerOptions()); err != nil {
finishExecution("Error while loading logger", map[string]interface{}{
"error": err.Error(),
})
}
}
func createLoggerOptions() *GoLogger.LoggerOptions {
return &GoLogger.LoggerOptions{
OutputFile: fmt.Sprintf("%s-log.json", appName),
Path: "log/",
LogLevel: getLogLevel(),
}
}
func getLogLevel() int {
levels := map[string]int{"DEBUG": GoLogger.DEBUG, "INFO": GoLogger.INFO,
"WARNING": GoLogger.WARNING, "ERROR": GoLogger.ERROR,
"PANIC": GoLogger.PANIC, "FATAL": GoLogger.FATAL,
}
if level, ok := levels[GoConfig.GetConfigStringValue("logLevel")]; ok {
return level
}
return GoLogger.INFO
}
func startApp() {
if err := GoCLI.StartCLI(createCLIOptions()); err != nil {
finishExecution("Error while starting application", map[string]interface{}{
"error": err.Error(),
})
}
}
func createCLIOptions() *GoCLI.Options {
return &GoCLI.Options{
AppName: appName,
AppUsage: "Tool to create different services in different languages and tooling to handle those services",
Commands: createCommands(),
}
}
func createCommands() []*GoCLI.Command {
return []*GoCLI.Command{
createServiceCommand(),
createToolingCommand(),
createOperationsCommand(),
createDeployCommand(),
}
}
func createServiceCommand() *GoCLI.Command {
return &GoCLI.Command{
Name: "create-service",
Usage: "Create a new service project in the language of your preference",
Action: generator.GenerateService,
StringFlags: getCreateServiceStringFlags(),
}
}
func getCreateServiceStringFlags() []*GoCLI.StringFlag {
return []*GoCLI.StringFlag{
createStringFlag("lang", "Language of the microservice to be created", "go"),
createStringFlag("repo-provider", "Service to handle repos(github, gitlab)", "github"),
createStringFlag("ci-provider", "Service to handle CI integration(travis)", "travis"),
}
}
func createToolingCommand() *GoCLI.Command {
return &GoCLI.Command{
Name: "create-tooling",
Usage: "Create a new tooling project to handle the services you previously created",
Action: generator.GenerateTooling,
StringFlags: getCreateToolingStringFlags(),
}
}
func createOperationsCommand() *GoCLI.Command {
return &GoCLI.Command{
Name: "create-operations",
Usage: "Create a new kubernetes project to handle the services you previously created",
Action: generator.GenerateOperations,
StringFlags: getCreateToolingStringFlags(),
}
}
func getCreateToolingStringFlags() []*GoCLI.StringFlag {
return []*GoCLI.StringFlag{
createStringFlag("services", "Space separated list of the services you want to manage", ""),
createStringFlag("repo-provider", "Service to handle repos(github, gitlab)", "github"),
}
}
func createDeployCommand() *GoCLI.Command {
return &GoCLI.Command{
Name: "deploy-service",
Usage: "Deploy a new service to one of the cloud providers(aws, gce, heroku)",
Action: generator.DeployService,
StringFlags: getDeployServiceStringFlags(),
}
}
func getDeployServiceStringFlags() []*GoCLI.StringFlag {
return []*GoCLI.StringFlag{
createStringFlag("provider", "Cloud provider(aws, gce, heroku)", "aws"),
}
}
func createStringFlag(name, usage, _default string) *GoCLI.StringFlag {
return &GoCLI.StringFlag{
Name: name,
Usage: usage,
Default: _default,
}
}
func finishExecution(msg string, fields map[string]interface{}) {
GoLogger.LogFatal(msg, fields)
}