changes project layout

This commit is contained in:
Holger Cremer
2018-08-25 15:18:40 +02:00
parent 1e9b3ed354
commit 02c7464ce2
18 changed files with 36 additions and 34 deletions

View File

@@ -4,10 +4,10 @@ import (
"fmt" "fmt"
"os" "os"
"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/ktt-ol/spaceDevices/mqtt" "github.com/ktt-ol/spaceDevices/internal/mqtt"
"github.com/ktt-ol/spaceDevices/webService" "github.com/ktt-ol/spaceDevices/internal/webService"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )

2
do.sh
View File

@@ -13,7 +13,7 @@ fi
while (( "$#" )); do while (( "$#" )); do
case "$1" in case "$1" in
build-linux) 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) test-sync)
rsync -n -avzi --delete spaceDevices webUI root@spacegate:/home/status/spaceDevices2/ rsync -n -avzi --delete spaceDevices webUI root@spacegate:/home/status/spaceDevices2/

View File

@@ -1,9 +1,9 @@
package conf_test package conf
import ( import (
"testing" "testing"
"github.com/ktt-ol/spaceDevices/conf" "github.com/ktt-ol/spaceDevices/internal/confrnal/conf"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"github.com/ktt-ol/spaceDevices/conf" "github.com/ktt-ol/spaceDevices/internal/conf"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View File

@@ -5,7 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"sync" "sync"
"github.com/ktt-ol/spaceDevices/conf" "github.com/ktt-ol/spaceDevices/internal/conf"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View File

@@ -3,8 +3,8 @@ package mqtt
import ( import (
"encoding/json" "encoding/json"
"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/sirupsen/logrus" "github.com/sirupsen/logrus"
"crypto/md5" "crypto/md5"
@@ -12,6 +12,7 @@ import (
"bytes" "bytes"
"sort" "sort"
"strings" "strings"
"github.com/ktt-ol/spaceDevices/pkg/structs"
) )
var ignoredVisibility = [...]db.Visibility{db.VisibilityCriticalInfrastructure, db.VisibilityImportantInfrastructure, var ignoredVisibility = [...]db.Visibility{db.VisibilityCriticalInfrastructure, db.VisibilityImportantInfrastructure,
@@ -22,7 +23,7 @@ var ddLogger = logrus.WithField("where", "deviceData")
type devicesEntry struct { type devicesEntry struct {
hideName bool hideName bool
showDevices bool showDevices bool
devices []Devices devices []structs.Devices
} }
type DeviceData struct { type DeviceData struct {
@@ -30,7 +31,7 @@ type DeviceData struct {
mqttHandler *MqttHandler mqttHandler *MqttHandler
masterDb db.MasterDb masterDb db.MasterDb
userDb db.UserDb userDb db.UserDb
wifiSessionList []WifiSession wifiSessionList []structs.WifiSession
lastSentHash []byte lastSentHash []byte
@@ -74,7 +75,7 @@ func (d *DeviceData) newData(data []byte) {
h := md5.New() h := md5.New()
s := fmt.Sprintf("%v", peopleAndDevices) s := fmt.Sprintf("%v", peopleAndDevices)
hash := h.Sum([]byte(s)) 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") ddLogger.Debug("Nothing changed in people count, skipping mqtt")
} else { } else {
d.mqttHandler.SendPeopleAndDevices(peopleAndDevices) 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 { for _, v := range d.wifiSessionList {
if v.Ip == ip { if v.Ip == ip {
return v, true return v, true
} }
} }
return WifiSession{}, false return structs.WifiSession{}, false
} }
func (d *DeviceData) parseWifiSessions(rawData []byte) (sessionsList []WifiSession, peopleAndDevices PeopleAndDevices, success bool) { func (d *DeviceData) parseWifiSessions(rawData []byte) (sessionsList []structs.WifiSession, peopleAndDevices structs.PeopleAndDevices, success bool) {
var sessionData map[string]WifiSession var sessionData map[string]structs.WifiSession
if err := json.Unmarshal(rawData, &sessionData); err != nil { if err := json.Unmarshal(rawData, &sessionData); err != nil {
ddLogger.WithFields(logrus.Fields{ ddLogger.WithFields(logrus.Fields{
"rawData": string(rawData), "rawData": string(rawData),
@@ -134,7 +135,7 @@ SESSION_LOOP:
username2DevicesMap[userInfo.Name] = entry 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) entry.devices = append(entry.devices, device)
if userInfo.Visibility == db.VisibilityIgnore { 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 { for username, devicesEntry := range username2DevicesMap {
if devicesEntry.hideName { if devicesEntry.hideName {
continue continue
} }
var person Person var person structs.Person
if devicesEntry.showDevices { if devicesEntry.showDevices {
person = Person{Name: username, Devices: devicesEntry.devices} person = structs.Person{Name: username, Devices: devicesEntry.devices}
sort.Sort(DevicesSorter(person.Devices)) sort.Sort(structs.DevicesSorter(person.Devices))
} else { } else {
person = Person{Name: username} person = structs.Person{Name: username}
} }
peopleAndDevices.People = append(peopleAndDevices.People, person) peopleAndDevices.People = append(peopleAndDevices.People, person)
} }
sort.Sort(PersonSorter(peopleAndDevices.People)) sort.Sort(structs.PersonSorter(peopleAndDevices.People))
success = true success = true
return return

View File

@@ -6,9 +6,9 @@ import (
"strconv" "strconv"
"testing" "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" "github.com/stretchr/testify/assert"
) )

View File

@@ -8,8 +8,9 @@ import (
"time" "time"
"github.com/eclipse/paho.mqtt.golang" "github.com/eclipse/paho.mqtt.golang"
"github.com/ktt-ol/spaceDevices/conf" "github.com/ktt-ol/spaceDevices/internal/conf"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/ktt-ol/spaceDevices/pkg/structs"
) )
const CLIENT_ID = "spaceDevicesGo" const CLIENT_ID = "spaceDevicesGo"
@@ -91,7 +92,7 @@ func (h *MqttHandler) GetNewDataChannel() chan []byte {
return h.newDataChan return h.newDataChan
} }
func (h *MqttHandler) SendPeopleAndDevices(data PeopleAndDevices) { func (h *MqttHandler) SendPeopleAndDevices(data structs.PeopleAndDevices) {
bytes, err := json.Marshal(data) bytes, err := json.Marshal(data)
if err != nil { if err != nil {
mqttLogger.Errorln("Invalid people json", err) mqttLogger.Errorln("Invalid people json", err)
@@ -198,7 +199,7 @@ func defaultCertPool(certFile string) *x509.CertPool {
} }
func emptyPeopleAndDevices() string { func emptyPeopleAndDevices() string {
pad := PeopleAndDevices{People: []Person{}} pad := structs.PeopleAndDevices{People: []structs.Person{}}
bytes, err := json.Marshal(pad) bytes, err := json.Marshal(pad)
if err != nil { if err != nil {
mqttLogger.WithError(err).Panic() mqttLogger.WithError(err).Panic()

View File

@@ -8,9 +8,9 @@ import (
"github.com/gin-contrib/gzip" "github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"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/ktt-ol/spaceDevices/mqtt" "github.com/ktt-ol/spaceDevices/internal/mqtt"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )

View File

@@ -1,4 +1,4 @@
package mqtt package structs
import ( import (
"strings" "strings"