Преглед изворни кода

chore: remove interface

master
Blaz Smehov пре 1 недеља
родитељ
комит
34cadb4cec
9 измењених фајлова са 10 додато и 9 уклоњено
  1. BIN
      bridge
  2. BIN
      decoder
  3. +2
    -0
      internal/app/bridge/app.go
  4. +2
    -1
      internal/app/decoder/app.go
  5. +4
    -7
      internal/pkg/bridge/handler.go
  6. +2
    -0
      internal/pkg/decoder/process.go
  7. +0
    -1
      internal/pkg/service/beacon_service.go
  8. BIN
      location
  9. BIN
      server


+ 2
- 0
internal/app/bridge/app.go Прегледај датотеку

@@ -3,6 +3,7 @@ package bridge
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"sync"
"time"
@@ -96,6 +97,7 @@ func (a *BridgeApp) Run(ctx context.Context) {
case msg := <-a.ChApi:
switch msg.Method {
case "POST":
fmt.Println("adding beacon to lookup", "mac", msg.MAC, "id", msg.ID)
a.AppState.AddBeaconToLookup(msg.MAC, msg.ID)
slog.Info("beacon added to lookup", "id", msg.ID)
case "DELETE":


+ 2
- 1
internal/app/decoder/app.go Прегледај датотеку

@@ -2,6 +2,7 @@ package decoder

import (
"context"
"fmt"
"log/slog"
"sync"
"time"
@@ -71,7 +72,6 @@ func (a *DecoderApp) Run(ctx context.Context) {
return
case <-healthTicker.C:
health, err := a.AppState.GetDecoderHealth(a.KafkaManager)
slog.Info("decoder health", "health", string(health))
if err != nil {
slog.Error("getting decoder health", "err", err)
continue
@@ -84,6 +84,7 @@ func (a *DecoderApp) Run(ctx context.Context) {
continue
}
case msg := <-a.ChRaw:
fmt.Println("msg: ", msg)
decoder.ProcessIncoming(msg, a.AppState, a.KafkaManager.GetWriter("alertbeacons"), a.ParserRegistry)
case msg := <-a.ChParser:
switch msg.ID {


+ 4
- 7
internal/pkg/bridge/handler.go Прегледај датотеку

@@ -3,6 +3,7 @@ package bridge
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"strings"
"time"
@@ -13,15 +14,10 @@ import (
"github.com/segmentio/kafka-go"
)

// BeaconLookup provides MAC->ID lookup (e.g. AppState).
type BeaconLookup interface {
BeaconExists(mac string) (id string, ok bool)
}

// HandleMQTTMessage processes an MQTT message: parses JSON array of RawReading or CSV.
// For JSON, converts each reading to BeaconAdvertisement and writes to the writer if MAC is in lookup.
// Hostname is derived from topic (e.g. "publish_out/gateway1" -> "gateway1"). Safe if topic has no "/".
func HandleMQTTMessage(topic string, payload []byte, lookup BeaconLookup, writer *kafka.Writer) {
func HandleMQTTMessage(topic string, payload []byte, appState *appcontext.AppState, writer *kafka.Writer) {
parts := strings.SplitN(topic, "/", 2)
hostname := ""
if len(parts) >= 2 {
@@ -39,10 +35,11 @@ func HandleMQTTMessage(topic string, payload []byte, lookup BeaconLookup, writer
if reading.Type == "Gateway" {
continue
}
id, ok := lookup.BeaconExists(reading.MAC)
id, ok := appState.BeaconExists(reading.MAC)
if !ok {
continue
}
fmt.Println("beacon found: ", id)
adv := appcontext.BeaconAdvertisement{
ID: id,
Hostname: hostname,


+ 2
- 0
internal/pkg/decoder/process.go Прегледај датотеку

@@ -30,6 +30,8 @@ func DecodeBeacon(adv appcontext.BeaconAdvertisement, appState *appcontext.AppSt
return nil
}

fmt.Println("beacon: ", beacon)

b, err := hex.DecodeString(beacon)
if err != nil {
return err


+ 0
- 1
internal/pkg/service/beacon_service.go Прегледај датотеку

@@ -18,7 +18,6 @@ import (
)

func findTracker(msg model.HTTPLocation, db *gorm.DB) (model.Tracker, error) {
fmt.Printf("Finding tracker for MAC: %s, ID: %s\n", msg.MAC, msg.ID)
var tracker model.Tracker
if msg.MAC != "" {
if err := db.Where("mac = ?", strings.ToUpper(strings.ReplaceAll(msg.MAC, ":", ""))).Find(&tracker).Error; err != nil {




Loading…
Откажи
Сачувај