fix: 调整 conns 添加 conn 的语句顺序,防止可能存在的程序卡死
This commit is contained in:
parent
c7327246a6
commit
9a595fa997
@ -29,9 +29,7 @@ func CreateConnection(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
conns[conn.Device.GetDeviceParams().Xaddr] = conn
|
||||
|
||||
info, err := conn.GetDeviceInformation()
|
||||
info, err := conn.GetDeviceInfo()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
@ -39,6 +37,9 @@ func CreateConnection(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// store connection
|
||||
conns[conn.Device.GetDeviceParams().Xaddr] = conn
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"device": info,
|
||||
})
|
||||
@ -48,7 +49,7 @@ func GetConnections(c *gin.Context) {
|
||||
devices := make(map[string]interface{})
|
||||
|
||||
for xaddr, conn := range conns {
|
||||
info, err := conn.GetDeviceInformation()
|
||||
info, err := conn.GetDeviceInfo()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
@ -75,7 +76,7 @@ func GetConnectionByXaddr(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
info, err := conn.GetDeviceInformation()
|
||||
info, err := conn.GetDeviceInfo()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
|
@ -13,6 +13,7 @@ func NewConnection(xaddr string, username string, password string) (*Connection,
|
||||
Xaddr: xaddr,
|
||||
Username: username,
|
||||
Password: password,
|
||||
AuthMode: onvif.DigestAuth,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -2,7 +2,7 @@ package onvif
|
||||
|
||||
import "github.com/IOTechSystems/onvif/device"
|
||||
|
||||
func (c *Connection) GetDeviceInformation() (*device.GetDeviceInformationResponse, error) {
|
||||
func (c *Connection) GetDeviceInfo() (*device.GetDeviceInformationResponse, error) {
|
||||
resp, err := c.Device.CallMethod(device.GetDeviceInformation{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user