mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 14:46:36 +08:00
[优化] response 结构调整
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"openflare/common/response"
|
||||
"openflare/controller/bind"
|
||||
"openflare/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -16,10 +18,10 @@ import (
|
||||
func GetProxyRoutes(c *gin.Context) {
|
||||
routes, err := service.ListProxyRoutes()
|
||||
if err != nil {
|
||||
respondFailure(c, err.Error())
|
||||
response.RespondFailure(c, err.Error())
|
||||
return
|
||||
}
|
||||
respondSuccess(c, routes)
|
||||
response.RespondSuccess(c, routes)
|
||||
}
|
||||
|
||||
// GetProxyRoute godoc
|
||||
@@ -32,16 +34,16 @@ func GetProxyRoutes(c *gin.Context) {
|
||||
// @Failure 400 {object} map[string]interface{}
|
||||
// @Router /api/proxy-routes/{id} [get]
|
||||
func GetProxyRoute(c *gin.Context) {
|
||||
id, ok := parseIDParam(c)
|
||||
id, ok := bind.IDParam(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
route, err := service.GetProxyRoute(id)
|
||||
if err != nil {
|
||||
respondFailure(c, err.Error())
|
||||
response.RespondFailure(c, err.Error())
|
||||
return
|
||||
}
|
||||
respondSuccess(c, route)
|
||||
response.RespondSuccess(c, route)
|
||||
}
|
||||
|
||||
// CreateProxyRoute godoc
|
||||
@@ -56,15 +58,15 @@ func GetProxyRoute(c *gin.Context) {
|
||||
// @Router /api/proxy-routes/ [post]
|
||||
func CreateProxyRoute(c *gin.Context) {
|
||||
var input service.ProxyRouteInput
|
||||
if !bindJSON(c, &input) {
|
||||
if !bind.JSON(c, &input) {
|
||||
return
|
||||
}
|
||||
route, err := service.CreateProxyRoute(input)
|
||||
if err != nil {
|
||||
respondFailure(c, err.Error())
|
||||
response.RespondFailure(c, err.Error())
|
||||
return
|
||||
}
|
||||
respondSuccess(c, route)
|
||||
response.RespondSuccess(c, route)
|
||||
}
|
||||
|
||||
// UpdateProxyRoute godoc
|
||||
@@ -79,20 +81,20 @@ func CreateProxyRoute(c *gin.Context) {
|
||||
// @Failure 400 {object} map[string]interface{}
|
||||
// @Router /api/proxy-routes/{id}/update [post]
|
||||
func UpdateProxyRoute(c *gin.Context) {
|
||||
id, ok := parseIDParam(c)
|
||||
id, ok := bind.IDParam(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var input service.ProxyRouteInput
|
||||
if !bindJSON(c, &input) {
|
||||
if !bind.JSON(c, &input) {
|
||||
return
|
||||
}
|
||||
route, err := service.UpdateProxyRoute(id, input)
|
||||
if err != nil {
|
||||
respondFailure(c, err.Error())
|
||||
response.RespondFailure(c, err.Error())
|
||||
return
|
||||
}
|
||||
respondSuccess(c, route)
|
||||
response.RespondSuccess(c, route)
|
||||
}
|
||||
|
||||
// DeleteProxyRoute godoc
|
||||
@@ -105,13 +107,13 @@ func UpdateProxyRoute(c *gin.Context) {
|
||||
// @Failure 400 {object} map[string]interface{}
|
||||
// @Router /api/proxy-routes/{id}/delete [post]
|
||||
func DeleteProxyRoute(c *gin.Context) {
|
||||
id, ok := parseIDParam(c)
|
||||
id, ok := bind.IDParam(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := service.DeleteProxyRoute(id); err != nil {
|
||||
respondFailure(c, err.Error())
|
||||
response.RespondFailure(c, err.Error())
|
||||
return
|
||||
}
|
||||
respondSuccess(c, nil)
|
||||
response.RespondSuccess(c, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user