mirror of
https://github.com/cedricve/go-onvif.git
synced 2025-09-27 04:45:54 +08:00
Fix GetDeviceInformation following guide
This commit is contained in:
24
device.go
24
device.go
@@ -1,7 +1,6 @@
|
||||
package onvif
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
@@ -33,9 +32,12 @@ func (device Device) GetDeviceInformation() (DeviceInformation, error) {
|
||||
|
||||
// Parse interface to struct
|
||||
result := DeviceInformation{}
|
||||
err = interfaceToStruct(&deviceInfo, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
if mapInfo, ok := deviceInfo.(map[string]interface{}); ok {
|
||||
result.Manufacturer = interfaceToString(mapInfo["Manufacturer"])
|
||||
result.Model = interfaceToString(mapInfo["Model"])
|
||||
result.FirmwareVersion = interfaceToString(mapInfo["FirmwareVersion"])
|
||||
result.SerialNumber = interfaceToString(mapInfo["SerialNumber"])
|
||||
result.HardwareID = interfaceToString(mapInfo["HardwareId"])
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -272,20 +274,6 @@ func (device Device) GetNetworkInterfaces() (string, error) {
|
||||
return DNS, nil
|
||||
}
|
||||
|
||||
func interfaceToStruct(src, dst interface{}) error {
|
||||
bt, err := json.Marshal(&src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(bt, &dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func interfaceToString(src interface{}) string {
|
||||
str, _ := src.(string)
|
||||
return str
|
||||
|
Reference in New Issue
Block a user