forked from FuturICT2/fin4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·72 lines (63 loc) · 2.11 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
package main
import (
"strings"
"github.com/FuturICT2/fin4-core/server/assetservice"
"github.com/FuturICT2/fin4-core/server/datatype"
"github.com/FuturICT2/fin4-core/server/dbservice"
"github.com/FuturICT2/fin4-core/server/emailer"
"github.com/FuturICT2/fin4-core/server/env"
"github.com/FuturICT2/fin4-core/server/ethereum"
"github.com/FuturICT2/fin4-core/server/filestorage"
"github.com/FuturICT2/fin4-core/server/logger"
"github.com/FuturICT2/fin4-core/server/routes"
"github.com/FuturICT2/fin4-core/server/timelineservice"
"github.com/FuturICT2/fin4-core/server/userservice"
)
func main() {
environment := strings.ToLower(env.MustGetenv("ENVIRONMENT"))
//TODO this should be changed ASAP
baseDir := "$GOPATH/src/github.com/FuturICT2/fin4-core"
env.Load(baseDir, false)
cfg := datatype.Config{
Environment: environment,
DBMigrationPath: env.MustGetenv("DB_MIGRATIONS_PATH"),
ServerPort: getPort(),
DataSourceName: env.MustGetenv("DATA_SOURCE_NAME"),
TestDataSourceName: env.Getenv("TEST_DATA_SOURCE_NAME"),
AwsSesKey: env.Getenv("AWS_SES_KEY"),
AwsSesSecret: env.Getenv("AWS_SES_SECRET"),
AwsEmailFrom: env.Getenv("EMAIL_FROM"),
SlackWebhookURL: env.Getenv("SLACK_WEBHOOK_URL"),
}
logger.Setup(cfg)
emailer.Setup(cfg)
// connect to database
db := dbservice.MustConnect(cfg.DataSourceName)
userService := userservice.NewService(db)
timelineService := timelineservice.NewService(db)
assetService := assetservice.NewService(db)
// connect with Amazon AWS (used in our live instance)
fs := filestorage.GetStorage(
env.Getenv("AWS_SES_KEY"),
env.Getenv("AWS_SES_SECRET"),
)
// connect with an instance of ethereum
ethereum := ethereum.MustNewEthereum()
sc := datatype.ServiceContainer{
Config: cfg,
AssetService: assetService,
TimelineService: timelineService,
UserService: userService,
FileStorage: fs,
Ethereum: ethereum,
}
// start listening to api calls
routes.SetupRouting(sc).Run(":" + cfg.ServerPort)
}
func getPort() string {
port := env.Getenv("PORT")
if port == "" {
port = "3000"
}
return port
}