-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (49 loc) · 1.24 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
package main
import (
"errors"
"flag"
"log"
"time"
"github.com/amirhnajafiz/jetstream-mirroring/internal/config"
"github.com/amirhnajafiz/jetstream-mirroring/internal/handlers"
)
const (
SVCProvider = "provider"
SVCConsumer = "consumer"
SVCBoot = "boot"
)
func main() {
var (
ServiceTypeFlag = flag.String("service", "bootstrap", "choose from boot/consumer/provider")
ConfigPathFlag = flag.String("config", "config.yaml", "config file path")
NATSHost = flag.String("nats", "localhost:4222", "nats host for the agent")
)
flag.Parse()
// load configs
cfg := config.Load(*ConfigPathFlag)
// create handler
h := handlers.Handler{
Stream: cfg.Stream,
ProviderInterval: time.Duration(cfg.Interval) * time.Second,
}
// start bootstrap
switch *ServiceTypeFlag {
case SVCConsumer:
if err := h.Consumer(*NATSHost); err != nil {
panic(err)
}
case SVCProvider:
if err := h.Provider(*NATSHost); err != nil {
panic(err)
}
case SVCBoot:
if err := h.Bootstrap(cfg.Clusters); len(err) > 0 {
for _, msg := range err {
log.Println(msg)
}
panic(errors.New("failed to bootstrap all clusters"))
}
default:
panic(errors.New("input service type is not in (provider, consumer, or boot)"))
}
}