mirror of
https://github.com/sascha-hemi/spaceDevices.git
synced 2026-03-21 01:04:24 +01:00
changes project layout
This commit is contained in:
@@ -4,10 +4,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/db"
|
||||
"github.com/ktt-ol/spaceDevices/mqtt"
|
||||
"github.com/ktt-ol/spaceDevices/webService"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/db"
|
||||
"github.com/ktt-ol/spaceDevices/internal/mqtt"
|
||||
"github.com/ktt-ol/spaceDevices/internal/webService"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
2
do.sh
2
do.sh
@@ -13,7 +13,7 @@ fi
|
||||
while (( "$#" )); do
|
||||
case "$1" in
|
||||
build-linux)
|
||||
env GOOS=linux GOARCH=amd64 go build cmd/spaceDevices.go
|
||||
env GOOS=linux GOARCH=amd64 go build cmd/spaceDevices/spaceDevices.go
|
||||
;;
|
||||
test-sync)
|
||||
rsync -n -avzi --delete spaceDevices webUI root@spacegate:/home/status/spaceDevices2/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package conf_test
|
||||
package conf
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/confrnal/conf"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -3,8 +3,8 @@ package mqtt
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/db"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/db"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"crypto/md5"
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"bytes"
|
||||
"sort"
|
||||
"strings"
|
||||
"github.com/ktt-ol/spaceDevices/pkg/structs"
|
||||
)
|
||||
|
||||
var ignoredVisibility = [...]db.Visibility{db.VisibilityCriticalInfrastructure, db.VisibilityImportantInfrastructure,
|
||||
@@ -22,7 +23,7 @@ var ddLogger = logrus.WithField("where", "deviceData")
|
||||
type devicesEntry struct {
|
||||
hideName bool
|
||||
showDevices bool
|
||||
devices []Devices
|
||||
devices []structs.Devices
|
||||
}
|
||||
|
||||
type DeviceData struct {
|
||||
@@ -30,7 +31,7 @@ type DeviceData struct {
|
||||
mqttHandler *MqttHandler
|
||||
masterDb db.MasterDb
|
||||
userDb db.UserDb
|
||||
wifiSessionList []WifiSession
|
||||
wifiSessionList []structs.WifiSession
|
||||
|
||||
lastSentHash []byte
|
||||
|
||||
@@ -74,7 +75,7 @@ func (d *DeviceData) newData(data []byte) {
|
||||
h := md5.New()
|
||||
s := fmt.Sprintf("%v", peopleAndDevices)
|
||||
hash := h.Sum([]byte(s))
|
||||
if bytes.Equal(hash, d.lastSentHash) {
|
||||
if bytes.Equal(hash, d.lastSentHash) {
|
||||
ddLogger.Debug("Nothing changed in people count, skipping mqtt")
|
||||
} else {
|
||||
d.mqttHandler.SendPeopleAndDevices(peopleAndDevices)
|
||||
@@ -84,18 +85,18 @@ func (d *DeviceData) newData(data []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DeviceData) GetByIp(ip string) (WifiSession, bool) {
|
||||
func (d *DeviceData) GetByIp(ip string) (structs.WifiSession, bool) {
|
||||
for _, v := range d.wifiSessionList {
|
||||
if v.Ip == ip {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
|
||||
return WifiSession{}, false
|
||||
return structs.WifiSession{}, false
|
||||
}
|
||||
|
||||
func (d *DeviceData) parseWifiSessions(rawData []byte) (sessionsList []WifiSession, peopleAndDevices PeopleAndDevices, success bool) {
|
||||
var sessionData map[string]WifiSession
|
||||
func (d *DeviceData) parseWifiSessions(rawData []byte) (sessionsList []structs.WifiSession, peopleAndDevices structs.PeopleAndDevices, success bool) {
|
||||
var sessionData map[string]structs.WifiSession
|
||||
if err := json.Unmarshal(rawData, &sessionData); err != nil {
|
||||
ddLogger.WithFields(logrus.Fields{
|
||||
"rawData": string(rawData),
|
||||
@@ -134,7 +135,7 @@ SESSION_LOOP:
|
||||
username2DevicesMap[userInfo.Name] = entry
|
||||
}
|
||||
|
||||
device := Devices{Name: userInfo.DeviceName, Location: d.findLocation(wifiSession.AP)}
|
||||
device := structs.Devices{Name: userInfo.DeviceName, Location: d.findLocation(wifiSession.AP)}
|
||||
entry.devices = append(entry.devices, device)
|
||||
|
||||
if userInfo.Visibility == db.VisibilityIgnore {
|
||||
@@ -162,22 +163,22 @@ SESSION_LOOP:
|
||||
}
|
||||
}
|
||||
|
||||
peopleAndDevices.People = make([]Person, 0, 10)
|
||||
peopleAndDevices.People = make([]structs.Person, 0, 10)
|
||||
for username, devicesEntry := range username2DevicesMap {
|
||||
if devicesEntry.hideName {
|
||||
continue
|
||||
}
|
||||
|
||||
var person Person
|
||||
var person structs.Person
|
||||
if devicesEntry.showDevices {
|
||||
person = Person{Name: username, Devices: devicesEntry.devices}
|
||||
sort.Sort(DevicesSorter(person.Devices))
|
||||
person = structs.Person{Name: username, Devices: devicesEntry.devices}
|
||||
sort.Sort(structs.DevicesSorter(person.Devices))
|
||||
} else {
|
||||
person = Person{Name: username}
|
||||
person = structs.Person{Name: username}
|
||||
}
|
||||
peopleAndDevices.People = append(peopleAndDevices.People, person)
|
||||
}
|
||||
sort.Sort(PersonSorter(peopleAndDevices.People))
|
||||
sort.Sort(structs.PersonSorter(peopleAndDevices.People))
|
||||
|
||||
success = true
|
||||
return
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
|
||||
"github.com/ktt-ol/spaceDevices/db"
|
||||
"github.com/ktt-ol/spaceDevices/internal/db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/ktt-ol/spaceDevices/pkg/structs"
|
||||
)
|
||||
|
||||
const CLIENT_ID = "spaceDevicesGo"
|
||||
@@ -91,7 +92,7 @@ func (h *MqttHandler) GetNewDataChannel() chan []byte {
|
||||
return h.newDataChan
|
||||
}
|
||||
|
||||
func (h *MqttHandler) SendPeopleAndDevices(data PeopleAndDevices) {
|
||||
func (h *MqttHandler) SendPeopleAndDevices(data structs.PeopleAndDevices) {
|
||||
bytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
mqttLogger.Errorln("Invalid people json", err)
|
||||
@@ -198,7 +199,7 @@ func defaultCertPool(certFile string) *x509.CertPool {
|
||||
}
|
||||
|
||||
func emptyPeopleAndDevices() string {
|
||||
pad := PeopleAndDevices{People: []Person{}}
|
||||
pad := structs.PeopleAndDevices{People: []structs.Person{}}
|
||||
bytes, err := json.Marshal(pad)
|
||||
if err != nil {
|
||||
mqttLogger.WithError(err).Panic()
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/gin-contrib/gzip"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/ktt-ol/spaceDevices/conf"
|
||||
"github.com/ktt-ol/spaceDevices/db"
|
||||
"github.com/ktt-ol/spaceDevices/mqtt"
|
||||
"github.com/ktt-ol/spaceDevices/internal/conf"
|
||||
"github.com/ktt-ol/spaceDevices/internal/db"
|
||||
"github.com/ktt-ol/spaceDevices/internal/mqtt"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mqtt
|
||||
package structs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
Reference in New Issue
Block a user