-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathmain.go
40 lines (32 loc) · 895 Bytes
/
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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
)
func envOrDefault(env string, def string) string {
value, exist := os.LookupEnv(env)
if !exist {
return def
}
return value
}
func main() {
host := envOrDefault("INFLUXDB_HOST", "localhost:8086")
token := envOrDefault("INFLUXDB_TOKEN", "")
clashHost := envOrDefault("CLASH_HOST", "localhost:9090")
clashToken := envOrDefault("CLASH_TOKEN", "")
client := influxdb2.NewClient(fmt.Sprintf("http://%s", host), token)
defer client.Close()
startQueue(client.WriteAPI("clash", "events"))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go handleTraffic(ctx, clashHost, clashToken)
go handleTracing(ctx, clashHost, clashToken)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
}