iptables-helper/internel/controller/controller.go

31 lines
831 B
Go
Raw Normal View History

2023-11-02 23:35:05 +08:00
package controller
import (
"github.com/gofiber/fiber/v2"
response "iptables-helper/pkg/resp"
"iptables-helper/pkg/utils/command"
"iptables-helper/pkg/utils/iptables"
)
func SetupController(r fiber.Router) {
api := r.Group("/")
getRuleInfo(api)
}
// getRuleInfo
// @Summary 获取 iptables 规则 信息
// @Description 获取 iptables 规则 信息
// @Tags Info
// @Accept json
// @Produce json
// @Success 200 {object} response.Response{data=iptables.Info}
// @Failure default {object} errorx.CodeErrorResponse
// @Router /info [get]
func getRuleInfo(api fiber.Router) {
api.Get("/info", func(ctx *fiber.Ctx) error {
cmder := command.Commander{}
result := cmder.ExecuteWithResult("sudo iptables -S")
return ctx.JSON(response.NewResponse(iptables.Parse(result)))
})
}