feat(handlers): Handle DELETE for environment sensors
It now works as advertised in the README! *ahem*...
This commit is contained in:
parent
abde10bfc9
commit
34d05ffa49
2 changed files with 27 additions and 4 deletions
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"git.hamburg.ccc.de/ccchh/spaceapid/types"
|
"git.hamburg.ccc.de/ccchh/spaceapid/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnvironmentSensor(
|
func EnvironmentSensorPUT(
|
||||||
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
||||||
resp *types.EnvironmentSensor,
|
resp *types.EnvironmentSensor,
|
||||||
) func(http.ResponseWriter, *http.Request) {
|
) func(http.ResponseWriter, *http.Request) {
|
||||||
|
|
@ -35,3 +35,20 @@ func EnvironmentSensor(
|
||||||
resp.LastChange = time.Now().Unix()
|
resp.LastChange = time.Now().Unix()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EnvironmentSensorDELETE(
|
||||||
|
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
||||||
|
resp *types.EnvironmentSensor,
|
||||||
|
) func(http.ResponseWriter, *http.Request) {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
_, err := updateEndpointValidator(authDB, validCredentials, w, r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set SpaceAPI response values
|
||||||
|
resp.Value = 0
|
||||||
|
resp.LastChange = time.Now().Unix()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
12
main.go
12
main.go
|
|
@ -68,12 +68,18 @@ func main() {
|
||||||
// Register handlers for environmental sensors
|
// Register handlers for environmental sensors
|
||||||
for sensorType, envSensorConfigs := range conf.Dynamic.Sensors {
|
for sensorType, envSensorConfigs := range conf.Dynamic.Sensors {
|
||||||
for i, envSensorConfig := range envSensorConfigs {
|
for i, envSensorConfig := range envSensorConfigs {
|
||||||
urlPattern := "PUT " + util.GetSensorURLPath(
|
urlPattern := util.GetSensorURLPath(
|
||||||
sensorType, envSensorConfig.SensorData.Location, envSensorConfig.SensorData.Name,
|
sensorType, envSensorConfig.SensorData.Location, envSensorConfig.SensorData.Name,
|
||||||
)
|
)
|
||||||
http.HandleFunc(
|
http.HandleFunc(
|
||||||
urlPattern,
|
"PUT "+urlPattern,
|
||||||
handlers.EnvironmentSensor(
|
handlers.EnvironmentSensorPUT(
|
||||||
|
conf.Credentials, envSensorConfig.AllowedCredentials, &conf.Response.Sensors[sensorType][i],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
http.HandleFunc(
|
||||||
|
"DELETE "+urlPattern,
|
||||||
|
handlers.EnvironmentSensorDELETE(
|
||||||
conf.Credentials, envSensorConfig.AllowedCredentials, &conf.Response.Sensors[sensorType][i],
|
conf.Credentials, envSensorConfig.AllowedCredentials, &conf.Response.Sensors[sensorType][i],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue