summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-06 17:57:56 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-06 17:57:56 +0530
commitaa57cfdf36407148af613e5633e264a22c4459de (patch)
treecc50a60eb852122d14c202b5d0008bc5589d6b44 /api
parent554975e37db43e1f0f26c740ec5593603d67f601 (diff)
api: init
Diffstat (limited to 'api')
-rw-r--r--api/main.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/api/main.go b/api/main.go
new file mode 100644
index 0000000..5ce05c1
--- /dev/null
+++ b/api/main.go
@@ -0,0 +1,46 @@
+package api
+
+import (
+ "log"
+ "net"
+
+ "sinanmohd.com/redq/usage"
+)
+
+const sockPath = "/tmp/redq_ebpf.sock"
+
+type Api struct {
+ sock net.Listener
+}
+
+func (a *Api) Init() error {
+ var err error
+
+ a.sock, err = net.Listen("unix", sockPath)
+ if err != nil {
+ log.Printf("listening on unix socket: %s", err)
+ return err
+ }
+
+ return nil
+}
+
+func handleConn(conn net.Conn) {
+ defer conn.Close()
+}
+
+func (a *Api) Run(u *usage.Usage) {
+ for {
+ conn, err := a.sock.Accept()
+ if err != nil {
+ log.Printf("accepting connection: %s", err)
+ continue
+ }
+
+ go handleConn(conn)
+ }
+}
+
+func (a *Api) CleanUp() {
+ a.sock.Close()
+}