refactor: 参数化 ONVIF 连接

This commit is contained in:
2024-08-22 12:51:23 +08:00
parent 66254725df
commit c7327246a6
2 changed files with 66 additions and 27 deletions

View File

@ -5,21 +5,12 @@ import (
)
type Connection struct {
Params DeviceParams `json:"params"`
Device *onvif.Device `json:"device"`
}
type DeviceParams struct {
Xaddr string `json:"xaddr"`
EndpointRefAddress string `json:"endpointRefAddress"`
Username string `json:"username"`
Password string `json:"password"`
AuthMode string `json:"authMode"`
}
func NewConnection(addr string, username string, password string) (*Connection, error) {
func NewConnection(xaddr string, username string, password string) (*Connection, error) {
dev, err := onvif.NewDevice(onvif.DeviceParams{
Xaddr: addr,
Xaddr: xaddr,
Username: username,
Password: password,
})
@ -27,14 +18,5 @@ func NewConnection(addr string, username string, password string) (*Connection,
return nil, err
}
return &Connection{
Params: DeviceParams{
Xaddr: dev.GetDeviceParams().Xaddr,
EndpointRefAddress: dev.GetDeviceParams().EndpointRefAddress,
Username: dev.GetDeviceParams().Username,
Password: dev.GetDeviceParams().Password,
AuthMode: dev.GetDeviceParams().AuthMode,
},
Device: dev,
}, nil
return &Connection{Device: dev}, nil
}