-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_deleteapi.go
executable file
·67 lines (58 loc) · 1.49 KB
/
func_deleteapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package authorized
import (
"net/http"
"github.com/zhimma/go-gin-api/internal/code"
"github.com/zhimma/go-gin-api/internal/pkg/core"
)
type deleteAPIRequest struct {
Id string `uri:"id"` // HashID
}
type deleteAPIResponse struct {
Id int32 `json:"id"` // 主键ID
}
// DeleteAPI 删除调用方接口地址
// @Summary 删除调用方接口地址
// @Description 删除调用方接口地址
// @Tags API.authorized
// @Accept json
// @Produce json
// @Param id path string true "主键ID"
// @Success 200 {object} deleteAPIResponse
// @Failure 400 {object} code.Failure
// @Router /api/authorized_api/{id} [delete]
// @Security LoginToken
func (h *handler) DeleteAPI() core.HandlerFunc {
return func(c core.Context) {
req := new(deleteAPIRequest)
res := new(deleteAPIResponse)
if err := c.ShouldBindURI(req); err != nil {
c.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
code.Text(code.ParamBindError)).WithError(err),
)
return
}
ids, err := h.hashids.HashidsDecode(req.Id)
if err != nil {
c.AbortWithError(core.Error(
http.StatusBadRequest,
code.HashIdsDecodeError,
code.Text(code.HashIdsDecodeError)).WithError(err),
)
return
}
id := int32(ids[0])
err = h.authorizedService.DeleteAPI(c, id)
if err != nil {
c.AbortWithError(core.Error(
http.StatusBadRequest,
code.AuthorizedDeleteAPIError,
code.Text(code.AuthorizedDeleteAPIError)).WithError(err),
)
return
}
res.Id = id
c.Payload(res)
}
}