-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (68 loc) · 1.56 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
package main
import (
"os"
"github.com/alexsward/steel/store"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
if err := app().Run(os.Args); err != nil {
zap.L().Error("error running application", zap.Error(err))
os.Exit(1)
}
}
func app() *cli.App {
return &cli.App{
Name: "steel",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Value: "INFO",
Required: false,
},
},
Before: func(ctx *cli.Context) error {
return setupLogger(ctx)
},
Action: func(ctx *cli.Context) error {
s, err := NewService(&ServiceConfig{
// TODO: make all of this dynamic
BackingStores: getBackingStoreConfiguration(),
Partitioner: MultiStorePartitionStrategy(2),
})
if err != nil {
zap.L().Error("error creating service", zap.Error(err))
}
go s.Run()
<-ctx.Done()
return nil
},
}
}
func getBackingStoreConfiguration() []BackingStore {
stores := make([]BackingStore, 0)
stores = append(stores, BackingStore{
Type: store.StoreTypeRedis,
Partition: 0,
Address: ":6379",
})
stores = append(stores, BackingStore{
Type: store.StoreTypeRedis,
Partition: 1,
Address: ":6380",
})
return stores
}
func setupLogger(ctx *cli.Context) error {
ecfg := zap.NewProductionEncoderConfig()
ecfg.EncodeTime = zapcore.RFC3339TimeEncoder
encoder := zapcore.NewConsoleEncoder(ecfg)
level, err := zapcore.ParseLevel(ctx.String("log-level"))
if err != nil {
return err
}
core := zapcore.NewCore(encoder, os.Stdout, level)
zap.ReplaceGlobals(zap.New(core))
return nil
}