Parcourir la source

chore: modify project structure, move types into internal package, define main package boilerplate

chore/proposed-structure
Blaz Smehov il y a 1 mois
Parent
révision
8e7689328d
6 fichiers modifiés avec 1746 ajouts et 0 suppressions
  1. +0
    -0
      cmd/presenSe/.keep
  2. +7
    -0
      cmd/presenSe/presense.go
  3. +0
    -0
      internal/pkg/model/.keep
  4. +3
    -0
      internal/pkg/model/model.md
  5. +168
    -0
      internal/pkg/model/types.go
  6. +1568
    -0
      main.go

cmd/_your_app_/.keep → cmd/presenSe/.keep Voir le fichier


+ 7
- 0
cmd/presenSe/presense.go Voir le fichier

@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("this is the main file")
}

internal/pkg/_your_private_lib_/.keep → internal/pkg/model/.keep Voir le fichier


+ 3
- 0
internal/pkg/model/model.md Voir le fichier

@@ -0,0 +1,3 @@
# MODELS

This file includes type definitions for aggregate struct types

+ 168
- 0
internal/pkg/model/types.go Voir le fichier

@@ -0,0 +1,168 @@
package model

import "sync"

// Settings defines configuration parameters for presence detection behavior.
type Settings struct {
Location_confidence int64 `json:"location_confidence"`
Last_seen_threshold int64 `json:"last_seen_threshold"`
Beacon_metrics_size int `json:"beacon_metrics_size"`
HA_send_interval int64 `json:"ha_send_interval"`
HA_send_changes_only bool `json:"ha_send_changes_only"`
}

// Incoming_json represents the JSON payload received from beacon messages.
type Incoming_json struct {
Hostname string `json:"hostname"`
MAC string `json:"mac"`
RSSI int64 `json:"rssi"`
Is_scan_response string `json:"is_scan_response"`
Ttype string `json:"type"`
Data string `json:"data"`
Beacon_type string `json:"beacon_type"`
UUID string `json:"uuid"`
Major string `json:"major"`
Minor string `json:"minor"`
TX_power string `json:"tx_power"`
Namespace string `json:"namespace"`
Instance_id string `json:"instance_id"`
// button stuff
HB_ButtonCounter int64 `json:"hb_button_counter"`
HB_ButtonCounter_Prev int64 `json:"hb_button_counter"`
HB_Battery int64 `json:"hb_button_battery"`
HB_RandomNonce string `json:"hb_button_random"`
HB_ButtonMode string `json:"hb_button_mode"`
}

// Advertisement describes a generic beacon advertisement payload.
type Advertisement struct {
ttype string
content string
seen int64
}

// BeaconMetric stores signal and distance data for a beacon.
type BeaconMetric struct {
location string
distance float64
rssi int64
timestamp int64
}

// Location defines a physical location and synchronization control.
type Location struct {
name string
lock sync.RWMutex
}

// BestLocation represents the most probable location of a beacon.
type BestLocation struct {
distance float64
name string
last_seen int64
}

// HTTPLocation describes a beacon's state as served over HTTP.
type HTTPLocation struct {
Previous_confident_location string `json:"previous_confident_location"`
Distance float64 `json:"distance"`
Name string `json:"name"`
Beacon_name string `json:"beacon_name"`
Beacon_id string `json:"beacon_id"`
Beacon_type string `json:"beacon_type"`
HB_Battery int64 `json:"hb_button_battery"`
HB_ButtonMode string `json:"hb_button_mode"`
HB_ButtonCounter int64 `json:"hb_button_counter"`
Location string `json:"location"`
Last_seen int64 `json:"last_seen"`
}

// LocationChange defines a change event for a beacon's detected location.
type LocationChange struct {
Beacon_ref Beacon `json:"beacon_info"`
Name string `json:"name"`
Beacon_name string `json:"beacon_name"`
Previous_location string `json:"previous_location"`
New_location string `json:"new_location"`
Timestamp int64 `json:"timestamp"`
}

// HAMessage represents a Home Assistant integration payload.
type HAMessage struct {
Beacon_id string `json:"id"`
Beacon_name string `json:"name"`
Distance float64 `json:"distance"`
}

// HTTPLocationsList aggregates all beacon HTTP states.
type HTTPLocationsList struct {
Beacons []HTTPLocation `json:"beacons"`
//Buttons []Button `json:"buttons"`
}

// Beacon holds all relevant information about a tracked beacon device.
type Beacon struct {
Name string `json:"name"`
Beacon_id string `json:"beacon_id"`
Beacon_type string `json:"beacon_type"`
Beacon_location string `json:"beacon_location"`
Last_seen int64 `json:"last_seen"`
Incoming_JSON Incoming_json `json:"incoming_json"`
Distance float64 `json:"distance"`
Previous_location string
Previous_confident_location string
expired_location string
Location_confidence int64
Location_history []string
beacon_metrics []BeaconMetric

HB_ButtonCounter int64 `json:"hb_button_counter"`
HB_ButtonCounter_Prev int64 `json:"hb_button_counter"`
HB_Battery int64 `json:"hb_button_battery"`
HB_RandomNonce string `json:"hb_button_random"`
HB_ButtonMode string `json:"hb_button_mode"`
}

// Button represents a hardware button beacon device.
type Button struct {
Name string `json:"name"`
Button_id string `json:"button_id"`
Button_type string `json:"button_type"`
Button_location string `json:"button_location"`
Incoming_JSON Incoming_json `json:"incoming_json"`
Distance float64 `json:"distance"`
Last_seen int64 `json:"last_seen"`

HB_ButtonCounter int64 `json:"hb_button_counter"`
HB_Battery int64 `json:"hb_button_battery"`
HB_RandomNonce string `json:"hb_button_random"`
HB_ButtonMode string `json:"hb_button_mode"`
}

// BeaconsList holds all known beacons and their synchronization lock.
type BeaconsList struct {
Beacons map[string]Beacon `json:"beacons"`
lock sync.RWMutex
}

// LocationsList holds all known locations with concurrency protection.
type LocationsList struct {
locations map[string]Location
lock sync.RWMutex
}

// Message defines the WebSocket or broadcast message payload.
type Message struct {
Email string `json:"email"`
Username string `json:"username"`
Message string `json:"message"`
}

// RawReading represents an incoming raw sensor reading.
type RawReading struct {
Timestamp string `json:"timestamp"`
Type string `json:"type"`
MAC string `json:"mac"`
RSSI int `json:"rssi"`
RawData string `json:"rawData"`
}

+ 1568
- 0
main.go
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


Chargement…
Annuler
Enregistrer