-
Notifications
You must be signed in to change notification settings - Fork 5
/
context.go
42 lines (36 loc) · 1.04 KB
/
context.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
package cmd
import (
"github.com/celer-network/im-executor/accounts"
"github.com/celer-network/im-executor/chains"
"github.com/celer-network/im-executor/dal"
"github.com/celer-network/im-executor/sgn"
"github.com/celer-network/im-executor/types"
"github.com/spf13/viper"
)
type ExecutorContext struct {
DB *dal.DB
Chains *chains.Chains
SgnClient *sgn.SgnClient
GatewayClient *sgn.GatewayClient
Accounts *accounts.Accounts
}
// cache for repeated ctx access
var ctx *ExecutorContext
func GetExecutorContext() *ExecutorContext {
if ctx == nil {
initExecutorContext()
}
return ctx
}
func initExecutorContext() {
testMode := viper.GetBool(FlagTest)
gatewayClient := sgn.NewGatewayClient(viper.GetString(types.KeyGatewayGrpcUrl), testMode)
sgnClient := sgn.NewSgnClient(viper.GetString(types.KeySgnGrpcUrl), testMode)
ctx = &ExecutorContext{
DB: dal.InitDB(),
Chains: chains.InitChains(),
SgnClient: sgnClient,
GatewayClient: gatewayClient,
Accounts: accounts.NewAccounts(),
}
}