fix(handlers): Handle DELETE for environment sensors
It now works as advertised in the README! *ahem*...
This commit is contained in:
parent
b54d4a39cd
commit
b054b02be6
2 changed files with 27 additions and 4 deletions
|
|
@ -11,7 +11,7 @@ import (
|
|||
"git.hamburg.ccc.de/ccchh/spaceapid/types"
|
||||
)
|
||||
|
||||
func EnvironmentSensor(
|
||||
func EnvironmentSensorPUT(
|
||||
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
||||
resp *types.EnvironmentSensor,
|
||||
) func(http.ResponseWriter, *http.Request) {
|
||||
|
|
@ -35,3 +35,20 @@ func EnvironmentSensor(
|
|||
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
|
||||
for sensorType, envSensorConfigs := range conf.Dynamic.Sensors {
|
||||
for i, envSensorConfig := range envSensorConfigs {
|
||||
urlPattern := "PUT " + util.GetSensorURLPath(
|
||||
urlPattern := util.GetSensorURLPath(
|
||||
sensorType, envSensorConfig.SensorData.Location, envSensorConfig.SensorData.Name,
|
||||
)
|
||||
http.HandleFunc(
|
||||
urlPattern,
|
||||
handlers.EnvironmentSensor(
|
||||
"PUT "+urlPattern,
|
||||
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],
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue