Initialize sensors map with static parts when parsing config

This commit is contained in:
Bendodroid 2024-01-14 01:02:30 +01:00
parent daac0b3b9e
commit 6e1a8ac0e6
Signed by: bendodroid
GPG key ID: 3EEE19A0F73D5FFC

View file

@ -7,6 +7,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"slices" "slices"
"gitlab.hamburg.ccc.de/ccchh/spaceapid/types"
) )
const ( const (
@ -50,5 +52,14 @@ func ParseConfiguration() (conf SpaceapidConfig) {
log.Fatalln("Provided file doesn't specify compatibility with API version 14") log.Fatalln("Provided file doesn't specify compatibility with API version 14")
} }
// Initialise fields for environment sensors
conf.Response.Sensors = make(map[string][]types.EnvironmentSensor)
for key, sensorConfigs := range conf.Dynamic.Sensors {
conf.Response.Sensors[key] = make([]types.EnvironmentSensor, len(sensorConfigs))
for i, sensorConfig := range sensorConfigs {
conf.Response.Sensors[key][i] = sensorConfig.SensorData
}
}
return return
} }