MQTTListener/env/env.go

40 lines
651 B
Go
Raw Normal View History

2020-09-02 09:02:30 +02:00
package env
import (
"mqttListener/config"
"mqttListener/models"
"fmt"
//"log"
"net/http"
)
type Env struct {
DB models.Datastore
Config *config.Config
}
func (env *Env) DevicesIndex(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, http.StatusText(405), 405)
return
}
devices, err := env.DB.AllDevices()
if err != nil {
http.Error(w, http.StatusText(500), 500)
return
}
for _, device := range devices {
2020-09-13 18:37:22 +02:00
fmt.Fprintf(w, "%s, %s, %s, %s, %s, %s, %s\n",
device.TOPIC,
device.CustomerID,
device.DeviceID,
device.ProjectName,
device.MAC,
device.SN,
device.LastMsg,
)
2020-09-02 09:02:30 +02:00
}
}