-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathmain.go
53 lines (46 loc) · 1.17 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
package main
import (
"context"
"flag"
"log"
"time"
"cloud.google.com/go/spanner"
"github.com/MixinNetwork/ocean.one/cache"
"github.com/MixinNetwork/ocean.one/config"
"github.com/MixinNetwork/ocean.one/persistence"
"github.com/go-redis/redis"
)
func main() {
service := flag.String("service", "http", "run a service")
flag.Parse()
ctx := context.Background()
spannerClient, err := spanner.NewClientWithConfig(ctx, config.GoogleCloudSpanner, spanner.ClientConfig{NumChannels: 4,
SessionPoolConfig: spanner.SessionPoolConfig{
HealthCheckInterval: 5 * time.Second,
},
})
if err != nil {
log.Panicln(err)
}
redisClient := redis.NewClient(&redis.Options{
Addr: config.RedisEngineCacheAddress,
DB: config.RedisEngineCacheDatabase,
ReadTimeout: 3 * time.Second,
WriteTimeout: 3 * time.Second,
PoolTimeout: 4 * time.Second,
IdleTimeout: 60 * time.Second,
PoolSize: 1024,
})
err = redisClient.Ping().Err()
if err != nil {
log.Panicln(err)
}
ctx = persistence.SetupSpanner(ctx, spannerClient)
ctx = cache.SetupRedis(ctx, redisClient)
switch *service {
case "engine":
NewExchange().Run(ctx)
case "http":
StartHTTP(ctx)
}
}