refactor: 迁移 service 代码逻辑
This commit is contained in:
31
service/onvif/session.go
Normal file
31
service/onvif/session.go
Normal file
@ -0,0 +1,31 @@
|
||||
package onvif
|
||||
|
||||
import (
|
||||
"github.com/IOTechSystems/onvif"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
Device *onvif.Device `json:"device"`
|
||||
}
|
||||
|
||||
var Sessions = make(map[string]*Session)
|
||||
|
||||
func NewSession(xaddr string, username string, password string) (*Session, error) {
|
||||
// 规范化连接地址
|
||||
if !strings.Contains(xaddr, ":") {
|
||||
xaddr += ":80"
|
||||
}
|
||||
|
||||
dev, err := onvif.NewDevice(onvif.DeviceParams{
|
||||
Xaddr: xaddr,
|
||||
Username: username,
|
||||
Password: password,
|
||||
AuthMode: onvif.DigestAuth,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Session{Device: dev}, nil
|
||||
}
|
Reference in New Issue
Block a user