Refactor rule commands to use nftCommand utilities for improved code reuse

This commit is contained in:
2026-04-26 16:12:24 +05:00
parent bc00e46865
commit 8d9c3e7f7b
2 changed files with 35 additions and 9 deletions
+5 -9
View File
@@ -1,11 +1,10 @@
package rule
import (
"strconv"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/contract"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/contract/nft"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/family"
nftCommand "git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/pkg/nft"
)
type rule struct {
@@ -19,24 +18,21 @@ func New(command contract.Command) nft.Rule {
}
func (r *rule) Add(family family.Type, tableName string, chainName string, expr ...string) error {
args := []string{"add", "rule", family.String(), tableName, chainName}
args = append(args, expr...)
args := nftCommand.RuleAdd(family, tableName, chainName, expr...)
return r.command.Run(args...)
}
func (r *rule) Insert(family family.Type, tableName string, chainName string, expr ...string) error {
args := []string{"insert", "rule", family.String(), tableName, chainName}
args = append(args, expr...)
args := nftCommand.RuleInsert(family, tableName, chainName, expr...)
return r.command.Run(args...)
}
func (r *rule) Replace(family family.Type, tableName string, chainName string, handle uint64, expr ...string) error {
args := []string{"replace", "rule", family.String(), tableName, chainName, "handle", strconv.Itoa(int(handle))}
args = append(args, expr...)
args := nftCommand.RuleReplace(family, tableName, chainName, handle, expr...)
return r.command.Run(args...)
}
func (r *rule) Delete(family family.Type, tableName string, chainName string, handle uint64) error {
args := []string{"delete", "rule", family.String(), tableName, chainName, "handle", strconv.Itoa(int(handle))}
args := nftCommand.RuleDelete(family, tableName, chainName, handle)
return r.command.Run(args...)
}