From fd737e632784aad2cf068bda61abaaab92b6e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=C5=A0ari=C4=87?= Date: Sun, 3 Dec 2023 11:20:17 +0100 Subject: [PATCH] exports device params, fixes error in comments, adds gitignore file --- .gitignore | 2 ++ Device.go | 35 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..29b636a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +*.iml \ No newline at end of file diff --git a/Device.go b/Device.go index 405af619..9f1e4265 100644 --- a/Device.go +++ b/Device.go @@ -17,7 +17,7 @@ import ( wsdiscovery "github.com/use-go/onvif/ws-discovery" ) -//Xlmns XML Scheam +// Xlmns XML Scheam var Xlmns = map[string]string{ "onvif": "http://www.onvif.org/ver10/schema", "tds": "http://www.onvif.org/ver10/device/wsdl", @@ -36,7 +36,7 @@ var Xlmns = map[string]string{ "wsaw": "http://www.w3.org/2006/05/addressing/wsdl", } -//DeviceType alias for int +// DeviceType alias for int type DeviceType int // Onvif Device Tyoe @@ -63,7 +63,7 @@ func (devType DeviceType) String() string { } } -//DeviceInfo struct contains general information about ONVIF device +// DeviceInfo struct contains general information about ONVIF device type DeviceInfo struct { Manufacturer string Model string @@ -72,9 +72,9 @@ type DeviceInfo struct { HardwareId string } -//Device for a new device of onvif and DeviceInfo -//struct represents an abstract ONVIF device. -//It contains methods, which helps to communicate with ONVIF device +// Device for a new device of onvif and DeviceInfo +// struct represents an abstract ONVIF device. +// It contains methods, which helps to communicate with ONVIF device type Device struct { params DeviceParams endpoints map[string]string @@ -88,16 +88,21 @@ type DeviceParams struct { HttpClient *http.Client } -//GetServices return available endpoints +// GetServices return available endpoints func (dev *Device) GetServices() map[string]string { return dev.endpoints } -//GetServices return available endpoints +// GetDeviceInfo return available endpoints func (dev *Device) GetDeviceInfo() DeviceInfo { return dev.info } +// GetDeviceParams return available endpoints +func (dev *Device) GetDeviceParams() DeviceParams { + return dev.params +} + func readResponse(resp *http.Response) string { b, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -106,7 +111,7 @@ func readResponse(resp *http.Response) string { return string(b) } -//GetAvailableDevicesAtSpecificEthernetInterface ... +// GetAvailableDevicesAtSpecificEthernetInterface ... func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) ([]Device, error) { // Call a ws-discovery Probe Message to Discover NVT type Devices devices, err := wsdiscovery.SendProbe(interfaceName, nil, []string{"dn:" + NVT.String()}, map[string]string{"dn": "http://www.onvif.org/ver10/network/wsdl"}) @@ -168,7 +173,7 @@ func (dev *Device) getSupportedServices(resp *http.Response) error { return nil } -//NewDevice function construct a ONVIF Device entity +// NewDevice function construct a ONVIF Device entity func NewDevice(params DeviceParams) (*Device, error) { dev := new(Device) dev.params = params @@ -209,7 +214,7 @@ func (dev *Device) addEndpoint(Key, Value string) { dev.endpoints[lowCaseKey] = Value } -//GetEndpoint returns specific ONVIF service endpoint address +// GetEndpoint returns specific ONVIF service endpoint address func (dev *Device) GetEndpoint(name string) string { return dev.endpoints[name] } @@ -229,7 +234,7 @@ func (dev Device) buildMethodSOAP(msg string) (gosoap.SoapMessage, error) { return soap, nil } -//getEndpoint functions get the target service endpoint in a better way +// getEndpoint functions get the target service endpoint in a better way func (dev Device) getEndpoint(endpoint string) (string, error) { // common condition, endpointMark in map we use this. @@ -250,8 +255,8 @@ func (dev Device) getEndpoint(endpoint string) (string, error) { return endpointURL, errors.New("target endpoint service not found") } -//CallMethod functions call an method, defined struct. -//You should use Authenticate method to call authorized requests. +// CallMethod functions call an method, defined struct. +// You should use Authenticate method to call authorized requests. func (dev Device) CallMethod(method interface{}) (*http.Response, error) { pkgPath := strings.Split(reflect.TypeOf(method).PkgPath(), "/") pkg := strings.ToLower(pkgPath[len(pkgPath)-1]) @@ -263,7 +268,7 @@ func (dev Device) CallMethod(method interface{}) (*http.Response, error) { return dev.callMethodDo(endpoint, method) } -//CallMethod functions call an method, defined struct with authentication data +// CallMethod functions call an method, defined struct with authentication data func (dev Device) callMethodDo(endpoint string, method interface{}) (*http.Response, error) { output, err := xml.MarshalIndent(method, " ", " ") if err != nil {