First implementation of new config format
- Functionally equivalent to old version at present - Temperature and Humidity sensors not handled yet - Moved HTTP handlers around
This commit is contained in:
parent
7bb676887f
commit
b2f62c7bb0
7 changed files with 125 additions and 121 deletions
30
util/util.go
30
util/util.go
|
@ -1,42 +1,18 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
|
||||
"gitlab.hamburg.ccc.de/ccchh/spaceapid/types"
|
||||
)
|
||||
|
||||
const savedStateJSONPath = "/var/lib/spaceapid/spaceapid-state.json"
|
||||
|
||||
// ParseTemplate parses the given file and
|
||||
func ParseTemplate(file string) (resp types.SpaceAPIResponseV14) {
|
||||
// Read template file
|
||||
template, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed reading file:", err)
|
||||
}
|
||||
|
||||
// Parse JSON
|
||||
dec := json.NewDecoder(bytes.NewReader(template))
|
||||
dec.DisallowUnknownFields()
|
||||
err = dec.Decode(&resp)
|
||||
if err != nil {
|
||||
log.Fatalln("Could not parse SpaceAPI response template:", err)
|
||||
}
|
||||
|
||||
// Check if compatible with v14
|
||||
if !slices.Contains(resp.APICompatibility, "14") {
|
||||
log.Fatalln("Provided template doesn't specify compatibility with API version 14")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
const (
|
||||
savedStateJSONPath = "/var/lib/spaceapid/spaceapid-state.json"
|
||||
)
|
||||
|
||||
// MergeOldState merges a given SpaceAPIResponse with the state saved at the time of last program exit and then deletes
|
||||
// the file containing the old state.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue