Generate HTTP endpoints for environment sensors
- Move update request sanity checks to new method in handlers/util.go - Change EnvironmentSensor.Value type because ParseFloat returns float64
This commit is contained in:
parent
6e1a8ac0e6
commit
38710484f9
5 changed files with 102 additions and 27 deletions
15
main.go
15
main.go
|
@ -1,10 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"gitlab.hamburg.ccc.de/ccchh/spaceapid/config"
|
||||
|
@ -37,6 +39,19 @@ func main() {
|
|||
http.HandleFunc("/state/open",
|
||||
handlers.StateOpen(conf.Credentials, conf.Dynamic.State.Open.AllowedCredentials, &conf.Response),
|
||||
)
|
||||
// Register handlers for Environmental Sensors
|
||||
for key, envSensorConfigs := range conf.Dynamic.Sensors {
|
||||
for i, envSensorConfig := range envSensorConfigs {
|
||||
http.HandleFunc(
|
||||
strings.ToLower(fmt.Sprintf(
|
||||
"/sensors/%s/%s/%s", key, envSensorConfig.SensorData.Location, envSensorConfig.SensorData.Name,
|
||||
)),
|
||||
handlers.EnvironmentSensor(
|
||||
conf.Credentials, envSensorConfig.AllowedCredentials, &conf.Response.Sensors[key][i],
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Start webserver
|
||||
log.Println("Starting HTTP server...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue