diff --git a/app/main.go b/app/main.go index fdc27ab..e9be97b 100644 --- a/app/main.go +++ b/app/main.go @@ -28,6 +28,8 @@ var ( Mysql, Clickhouse *sqlx.DB json = jsoniter.ConfigCompatibleWithStandardLibrary + + socketServer = make(chan []byte, 100) save = make(chan saveData, 100) slog = make(chan saveLog, 100) @@ -54,6 +56,7 @@ func main() { go announceCount() go saveDB() go saveLogs() + go socketHandler() http.HandleFunc("/cmd/", cmdHandler) http.HandleFunc("/list/", listHandler) @@ -88,6 +91,19 @@ func initClickhouse() { Clickhouse = db } +func socketHandler() { + for { + select { + case b := <-socketServer: + conn, err := net.Dial("unix", "/tmp/echo.sock") + if err == nil { + conn.Write(b) + conn.Close() + } + } + } +} + func randInt(min int, max int) int { return min + rand.Intn(max-min) } diff --git a/app/save.go b/app/save.go index f766a0f..397f1e6 100644 --- a/app/save.go +++ b/app/save.go @@ -131,16 +131,18 @@ func saveDB() { if m.Amount > 99 { msg, err := json.Marshal(struct { + Chanel string `json:"chanel"` Room string `json:"room"` Donator string `json:"donator"` Amount int64 `json:"amount"` }{ + Chanel: "chaturbate", Room: m.Room, Donator: m.From, Amount: m.Amount, }) if err == nil { - ws.Send <- msg + socketServer <- msg } } @@ -154,10 +156,14 @@ func saveDB() { if minutes >= 5 && now > index["last"]+30 { seconds += minutes * 60 msg, err := json.Marshal(struct { - Index int64 `json:"index"` - }{Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100}) + Chanel string `json:"chanel"` + Index int64 `json:"index"` + }{ + Chanel: "chaturbate", + Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100 + }) if err == nil { - ws.Send <- msg + socketServer <- msg } index["last"] = now } diff --git a/app/worker.go b/app/worker.go index ddf684f..7a77bad 100644 --- a/app/worker.go +++ b/app/worker.go @@ -56,10 +56,14 @@ func announceCount() { rooms.Count <- 0 l := <-rooms.Count msg, err := json.Marshal(struct { - Count int `json:"count"` - }{Count: l}) + Chanel string `json:"chanel"` + Count int `json:"count"` + }{ + Chanel: "chaturbate", + Count: l + }) if err == nil { - ws.Send <- msg + socketServer <- msg } } }