This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
forked from influxdata/influxdb-relay
-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.go
72 lines (58 loc) · 1.35 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 (
"flag"
"fmt"
"log"
"os"
"os/signal"
"github.com/strike-team/influxdb-relay/config"
"github.com/strike-team/influxdb-relay/relayservice"
)
const (
relayVersion = "3.1.0"
)
var (
usage = func() {
fmt.Println("Please, see README for more information about InfluxDB Relay...")
flag.PrintDefaults()
}
configFile = flag.String("config", "", "Configuration file to use")
verbose = flag.Bool("v", false, "If set, InfluxDB Relay will log HTTP requests")
versionFlag = flag.Bool("version", false, "Print current InfluxDB Relay version")
)
func runRelay(cfg config.Config) {
relay, err := relayservice.New(cfg)
if err != nil {
log.Fatal(err)
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
go func() {
<-sigChan
relay.Stop()
}()
log.Println("starting relays...")
relay.Run()
}
func main() {
flag.Usage = usage
flag.Parse()
if *versionFlag {
fmt.Println("influxdb-relay version " + relayVersion)
return
}
// Configuration file is mandatory
if *configFile == "" {
fmt.Fprintln(os.Stderr, "Missing configuration file")
flag.PrintDefaults()
os.Exit(1)
}
// And it has to be loaded in order to continue
cfg, err := config.LoadConfigFile(*configFile)
if err != nil {
log.Println("Version: " + relayVersion)
log.Fatal(err.Error())
}
cfg.Verbose = *verbose
runRelay(cfg)
}