Fix GetDeviceInformation following guide

This commit is contained in:
Radhi Fadlillah
2017-05-22 18:40:00 +07:00
parent 2e984a0379
commit 8332365c35

View File

@@ -1,7 +1,6 @@
package onvif package onvif
import ( import (
"encoding/json"
"fmt" "fmt"
"strings" "strings"
) )
@@ -33,9 +32,12 @@ func (device Device) GetDeviceInformation() (DeviceInformation, error) {
// Parse interface to struct // Parse interface to struct
result := DeviceInformation{} result := DeviceInformation{}
err = interfaceToStruct(&deviceInfo, &result) if mapInfo, ok := deviceInfo.(map[string]interface{}); ok {
if err != nil { result.Manufacturer = interfaceToString(mapInfo["Manufacturer"])
return result, err result.Model = interfaceToString(mapInfo["Model"])
result.FirmwareVersion = interfaceToString(mapInfo["FirmwareVersion"])
result.SerialNumber = interfaceToString(mapInfo["SerialNumber"])
result.HardwareID = interfaceToString(mapInfo["HardwareId"])
} }
return result, nil return result, nil
@@ -272,20 +274,6 @@ func (device Device) GetNetworkInterfaces() (string, error) {
return DNS, nil 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 { func interfaceToString(src interface{}) string {
str, _ := src.(string) str, _ := src.(string)
return str return str