summaryrefslogtreecommitdiff
path: root/api/main.go
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-07 08:32:11 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-07 08:32:11 +0530
commit87b230e71a830e191dd5c14aa94a025c39792145 (patch)
treee85c8fc6154f9f1f9d7aef3045fd31f61a9498ee /api/main.go
parenta1692f732078adad272256639f7a3ff14c9e643a (diff)
api/usage: init
Diffstat (limited to 'api/main.go')
-rw-r--r--api/main.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/api/main.go b/api/main.go
index 7081d3c..32f7d08 100644
--- a/api/main.go
+++ b/api/main.go
@@ -1,10 +1,12 @@
package api
import (
+ "context"
"encoding/json"
"log"
"net"
+ "sinanmohd.com/redq/db"
"sinanmohd.com/redq/usage"
)
@@ -40,7 +42,7 @@ func New() (*Api, error) {
return &a, nil
}
-func (a *Api) Run(u *usage.Usage) {
+func (a *Api) Run(u *usage.Usage, queries *db.Queries, ctxDb context.Context) {
for {
conn, err := a.sock.Accept()
if err != nil {
@@ -48,11 +50,11 @@ func (a *Api) Run(u *usage.Usage) {
continue
}
- go handleConn(conn, u)
+ go handleConn(conn, u, queries, ctxDb)
}
}
-func handleConn(conn net.Conn, u *usage.Usage) {
+func handleConn(conn net.Conn, u *usage.Usage, queries *db.Queries, ctxDb context.Context) {
defer conn.Close()
var req ApiReq
buf := make([]byte, bufSize)
@@ -72,6 +74,8 @@ func handleConn(conn net.Conn, u *usage.Usage) {
switch req.Type {
case "bandwidth":
handleBandwidth(conn, u)
+ case "usage":
+ handleUsage(conn, u, queries, ctxDb)
default:
log.Printf("invalid request type: %s", req.Type)
}