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, £%.2f\n", device.ID, device.MAC, device.SN, device.LastMsg) } }