feat(response): 统一结构返回
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"onvif-agent/config"
|
||||
"onvif-agent/response"
|
||||
)
|
||||
|
||||
func CreateEventSubscription(c *gin.Context) {
|
||||
@ -17,21 +18,17 @@ func CreateEventSubscription(c *gin.Context) {
|
||||
|
||||
conn := conns[xaddr]
|
||||
if conn == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "Connection not found",
|
||||
})
|
||||
response.NewResponse().Fail("Connection not found").WithCode(http.StatusNotFound).Send(c)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := conn.SubscribeEvents(callbackURL, "PT60S")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
response.NewResponse().Error(err).Send(c)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
response.NewResponse().Success().WithData(result).Send(c)
|
||||
}
|
||||
|
||||
func EventNotifyCallback(c *gin.Context) {
|
||||
@ -41,7 +38,7 @@ func EventNotifyCallback(c *gin.Context) {
|
||||
var notify event.Notify
|
||||
envelope := gosoap.NewSOAPEnvelope(¬ify)
|
||||
if err := c.ShouldBindXML(&envelope); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
response.NewResponse().Error(err).WithCode(http.StatusBadRequest).Send(c)
|
||||
return
|
||||
}
|
||||
|
||||
@ -50,5 +47,5 @@ func EventNotifyCallback(c *gin.Context) {
|
||||
log.Printf("Topic: %s, Message: %s", msg.Topic.TopicKinds, msg.Message.Message)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "OK"})
|
||||
response.NewResponse().Success().Send(c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user