refactor(router): 改为结构化 web 项目
This commit is contained in:
41
router/handler/onvif/connection.go
Normal file
41
router/handler/onvif/connection.go
Normal file
@ -0,0 +1,41 @@
|
||||
package onvif
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"onvif-agent/service/onvif"
|
||||
)
|
||||
|
||||
var conns = make(map[string]*onvif.Connection)
|
||||
|
||||
func CreateConnection(c *gin.Context) {
|
||||
conn, err := onvif.NewConnection("172.16.19.239", "admin", "admin123")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
conns[conn.Device.GetDeviceParams().Xaddr] = conn
|
||||
|
||||
info, err := conn.GetDeviceInformation()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"connectionParams": conn.Params,
|
||||
"deviceInfo": info,
|
||||
})
|
||||
}
|
||||
|
||||
func GetConnections(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, conns)
|
||||
}
|
||||
|
||||
func GetConnectionByXaddr(c *gin.Context) {
|
||||
xaddr := c.Param("xaddr")
|
||||
c.JSON(http.StatusOK, conns[xaddr])
|
||||
}
|
||||
|
||||
func DeleteConnection(c *gin.Context) {
|
||||
xaddr := c.Param("xaddr")
|
||||
delete(conns, xaddr)
|
||||
}
|
Reference in New Issue
Block a user