-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathonvifClient.go
53 lines (41 loc) · 1.13 KB
/
onvifClient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package onvif4go
import (
"time"
"github.com/faceterteam/onvif4go/soap"
)
type onvifCaller interface {
Call(request, response interface{}, headers ...interface{}) error
WithoutAuth() onvifCaller
SetLogger(logRequest, logResponse func(message string))
}
type onvifAuth struct {
login string
password string
timeDiff time.Duration
}
type onvifClient struct {
soapClient *soap.SoapClient
auth *onvifAuth
}
func NewOnvifClient(endpoint string, auth *onvifAuth) *onvifClient {
return &onvifClient{
soapClient: soap.NewSoapClient(endpoint),
auth: auth,
}
}
func (c *onvifClient) Call(request, response interface{}, headers ...interface{}) error {
if c.auth.login != "" {
headers = append(headers, soap.MakeWSSecurity(c.auth.login, c.auth.password, c.auth.timeDiff))
}
return c.soapClient.Do(request, response, headers...)
}
func (c *onvifClient) SetLogger(logRequest, logResponse func(message string)) {
c.soapClient.LogRequest = logRequest
c.soapClient.LogResponse = logResponse
}
func (c *onvifClient) WithoutAuth() onvifCaller {
return &onvifClient{
soapClient: c.soapClient,
auth: &onvifAuth{},
}
}