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