@@ -32,35 +32,51 @@ func AddChain(c *gin.Context) {
32
32
33
33
// DelChain DELETE /chain/{table}/{name}/
34
34
func DelChain (c * gin.Context ) {
35
- w := c .Writer
36
35
37
36
if ! checkRole (c ) {
37
+ c .AbortWithStatusJSON (http .StatusUnauthorized , forms.BasicResponse {
38
+ Ok : false ,
39
+ Message : "" ,
40
+ })
38
41
return
39
42
}
40
43
41
44
ipt , err := iptables .New ()
42
45
if err != nil {
43
- http .Error (w , err .Error (), 500 )
46
+ c .AbortWithStatusJSON (http .StatusInternalServerError , forms.BasicResponse {
47
+ Ok : false ,
48
+ Message : err .Error (),
49
+ })
44
50
return
45
51
}
46
52
// Clear chain before delete
47
- respErr = ipt .ClearChain (c .Param ("table" ), c .Param ("name" ))
48
- if respErr != nil {
49
- w .WriteHeader (http .StatusBadRequest )
50
- fmt .Fprintln (w , respErr )
53
+ err = ipt .ClearChain (c .Param ("table" ), c .Param ("name" ))
54
+ if err != nil {
55
+ c .AbortWithStatusJSON (http .StatusBadRequest , forms.BasicResponse {
56
+ Ok : false ,
57
+ Message : err .Error (),
58
+ })
59
+ return
51
60
}
52
61
// Delete chain
53
- respErr = ipt .DeleteChain (c .Param ("table" ), c .Param ("name" ))
62
+ err = ipt .DeleteChain (c .Param ("table" ), c .Param ("name" ))
54
63
if respErr != nil {
55
- w .WriteHeader (http .StatusBadRequest )
56
- fmt .Fprintln (w , respErr )
64
+ c .JSON (http .StatusInternalServerError , forms.ChainListResponse {
65
+ Ok : false ,
66
+ Message : err .Error (),
67
+ })
57
68
}
69
+
70
+ c .JSON (http .StatusOK , forms.ChainListResponse {
71
+ Ok : true ,
72
+ Message : "" ,
73
+ })
58
74
}
59
75
60
76
// ListChain GET /chain/{table}/{name}/
61
77
func ListChain (c * gin.Context ) {
62
78
if ! checkRole (c ) {
63
- c .AbortWithStatusJSON (http .StatusUnauthorized , forms.BasicResponse {
79
+ c .AbortWithStatusJSON (http .StatusUnauthorized , forms.ChainListResponse {
64
80
Ok : false ,
65
81
Message : "" ,
66
82
})
@@ -69,15 +85,15 @@ func ListChain(c *gin.Context) {
69
85
70
86
ipt , err := iptables .New ()
71
87
if err != nil {
72
- c .AbortWithStatusJSON (http .StatusInternalServerError , forms.BasicResponse {
88
+ c .AbortWithStatusJSON (http .StatusInternalServerError , forms.ChainListResponse {
73
89
Ok : false ,
74
90
Message : err .Error (),
75
91
})
76
92
return
77
93
}
78
94
respStr , err := ipt .List (c .Param ("table" ), c .Param ("name" ))
79
95
if err != nil {
80
- c .AbortWithStatusJSON (http .StatusInternalServerError , forms.BasicResponse {
96
+ c .AbortWithStatusJSON (http .StatusInternalServerError , forms.ChainListResponse {
81
97
Ok : false ,
82
98
Message : err .Error (),
83
99
})
0 commit comments