40 lines
651 B
Go
40 lines
651 B
Go
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 {
|
|
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,
|
|
)
|
|
}
|
|
}
|