v0.2.0 #3

Merged
kor-elf merged 22 commits from develop into main 2026-04-26 16:50:47 +05:00
Showing only changes of commit 9cd17572b2 - Show all commits
+72
View File
@@ -0,0 +1,72 @@
package nft
import (
"fmt"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/contract"
contractBatch "git.kor-elf.net/kor-elf-shield/go-nftables-client/contract/batch"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/batch"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/batch/chain"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/batch/rule"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/batch/table"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/pkg"
)
type batchBuilder struct {
command contract.CommandRun
file *pkg.File
table contractBatch.Table
chain contractBatch.Chain
rule contractBatch.Rule
isBuildBatch bool
}
func NewBatchBuilder(dir string) (contract.BatchBuilder, error) {
file, err := pkg.CreateRandomTmpFile(dir)
if err != nil {
return nil, err
}
command := batch.NewCommand(file)
return &batchBuilder{
command: command,
file: file,
table: table.New(command),
chain: chain.New(command),
rule: rule.New(command),
isBuildBatch: false,
}, nil
}
func (b *batchBuilder) Clear() error {
return fmt.Errorf("not implemented")
}
func (b *batchBuilder) Table() contractBatch.Table {
return b.table
}
func (b *batchBuilder) Chain() contractBatch.Chain {
return b.chain
}
func (b *batchBuilder) Rule() contractBatch.Rule {
return b.rule
}
func (b *batchBuilder) Build() contract.Batch {
b.isBuildBatch = true
return batch.NewBatch(b.file)
}
func (b *batchBuilder) Close() error {
if b.isBuildBatch {
return nil
}
return b.file.Remove()
}