summaryrefslogtreecommitdiff
path: root/cmd/main.go
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-07 10:46:54 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-07 10:46:54 +0530
commit38bf443cb2f52bd4cc822e69f9339094d846396f (patch)
treec5b84fa35a5339f1708b97c4b67c12e3ecd5dfc2 /cmd/main.go
parentb80d81a5cacc146b7bf7c92a716858d72cefb2be (diff)
cmd/redq -> cmd
Diffstat (limited to 'cmd/main.go')
-rw-r--r--cmd/main.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/cmd/main.go b/cmd/main.go
new file mode 100644
index 0000000..6597749
--- /dev/null
+++ b/cmd/main.go
@@ -0,0 +1,58 @@
+package main
+
+import (
+ "context"
+ "log"
+ "net"
+ "os"
+ "os/signal"
+ "syscall"
+
+ "github.com/jackc/pgx/v5"
+ "sinanmohd.com/redq/api"
+ "sinanmohd.com/redq/db"
+ "sinanmohd.com/redq/usage"
+ "sinanmohd.com/redq/dns"
+)
+
+func main() {
+ iface, err := net.InterfaceByName("wlan0")
+ if err != nil {
+ log.Fatalf("lookup network: %s", err)
+ }
+
+ ctx := context.Background()
+ conn, err := pgx.Connect(ctx, "user=redq_ebpf dbname=redq_ebpf")
+ if err != nil {
+ log.Fatalf("connecting database: %s", err)
+ }
+ defer conn.Close(ctx)
+ queries := db.New(conn)
+
+ d, err := dns.New()
+ if err != nil {
+ os.Exit(0)
+ }
+ a, err := api.New()
+ if err != nil {
+ os.Exit(0)
+ }
+ u, err := usage.New(iface)
+ if err != nil {
+ os.Exit(0)
+ }
+
+ sigs := make(chan os.Signal, 1)
+ signal.Notify(sigs, os.Interrupt, os.Kill, syscall.SIGTERM)
+ go func() {
+ <-sigs
+ usage.Close(u, queries, ctx)
+ api.Close(a)
+ os.Exit(0)
+ }()
+
+ go u.Run(iface, queries, ctx)
+ go d.Run()
+
+ a.Run(u, queries, ctx)
+}