This commit is contained in:
2026-03-07 16:45:29 +01:00
parent 87510c10c4
commit 4f57fd094e

View File

@@ -1,6 +1,7 @@
package speedport
import (
"encoding/json"
"fmt"
"strconv"
"strings"
@@ -8,12 +9,37 @@ import (
// VarEntry represents a single entry in the Speedport JSON response.
// The router returns an array of these objects.
// varvalue can be a string or a nested array; we normalise both to string.
type VarEntry struct {
VarType string `json:"vartype"`
VarID string `json:"varid"`
VarValue string `json:"varvalue"`
}
func (e *VarEntry) UnmarshalJSON(data []byte) error {
type plain struct {
VarType string `json:"vartype"`
VarID string `json:"varid"`
VarValue json.RawMessage `json:"varvalue"`
}
var p plain
if err := json.Unmarshal(data, &p); err != nil {
return err
}
e.VarType = p.VarType
e.VarID = p.VarID
// varvalue is either a quoted string or an array/object — store raw JSON for non-strings
if len(p.VarValue) > 0 && p.VarValue[0] == '"' {
if err := json.Unmarshal(p.VarValue, &e.VarValue); err != nil {
return err
}
} else {
e.VarValue = string(p.VarValue)
}
return nil
}
// StatusData holds all parsed status information from the router.
type StatusData struct {
Raw []VarEntry // Raw entries as returned by the router