This repository has been archived by the owner on Dec 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
90 lines (75 loc) · 2.12 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
package main
import (
"strconv"
"github.com/asaskevich/EventBus"
"github.com/short-d/app/fw"
"github.com/short-d/app/modern/mdevent"
"github.com/short-d/kgs/app"
"github.com/short-d/kgs/cmd"
"github.com/short-d/kgs/dep"
)
func main() {
env := dep.InitEnvironment()
env.AutoLoadDotEnvFile()
serviceName := env.GetEnv("SERVICE_NAME", "Kgs")
serviceEmailAddress := env.GetEnv("SERVICE_EMAIL", "kgs@localhost")
host := env.GetEnv("DB_HOST", "localhost")
port := mustInt(env.GetEnv("DB_PORT", "5432"))
user := env.GetEnv("DB_USER", "postgres")
password := env.GetEnv("DB_PASSWORD", "password")
dbName := env.GetEnv("DB_NAME", "kgs")
isEncryptionEnabled := mustBool(env.GetEnv("ENABLE_ENCRYPTION", ""))
certFilePath := env.GetEnv("CERT_FILE_PATH", "")
keyFilePath := env.GetEnv("KEY_FILE_PATH", "")
gRpcAPIPort := mustInt(env.GetEnv("GRPC_API_PORT", "8080"))
sendGridAPIKey := env.GetEnv("SEND_GRID_API_KEY", "")
CacheSize := mustInt(env.GetEnv("CACHE_SIZE", "100"))
config := app.Config{
LogLevel: fw.LogInfo,
ServiceName: serviceName,
ServiceEmailAddress: serviceEmailAddress,
MigrationRoot: "app/adapter/db/migration",
GRpcAPIPort: gRpcAPIPort,
SendGridAPIKey: sendGridAPIKey,
TemplateRootDir: "app/adapter/template",
CacheSize: CacheSize,
}
dbConfig := fw.DBConfig{
Host: host,
Port: port,
User: user,
Password: password,
DbName: dbName,
}
dbConnector := dep.InitDBConnector()
dbMigrationTool := dep.InitDBMigrationTool()
securityPolicy := fw.SecurityPolicy{
IsEncrypted: isEncryptionEnabled,
CertificateFilePath: certFilePath,
KeyFilePath: keyFilePath,
}
eventDispatcher := mdevent.NewEventDispatcher(EventBus.New())
rootCmd := cmd.NewRootCmd(
config,
dbConfig,
dbConnector,
dbMigrationTool,
securityPolicy,
eventDispatcher,
)
cmd.Execute(rootCmd)
}
func mustInt(numStr string) int {
num, err := strconv.Atoi(numStr)
if err != nil {
panic(err)
}
return num
}
func mustBool(boolStr string) bool {
boolean, err := strconv.ParseBool(boolStr)
if err != nil {
panic(err)
}
return boolean
}