chore: add new formatter to .golangci.yml
All checks were successful
build / build (push) Successful in 2m23s

This commit is contained in:
d3m0k1d
2026-01-19 18:57:11 +03:00
parent a1321300cb
commit 46dc54f5a7
8 changed files with 80 additions and 11 deletions

View File

@@ -12,10 +12,12 @@ linters:
- govet
- staticcheck
- gosec
- nilerr
formatters:
enable:
- gofmt
- goimports
- golines

View File

@@ -62,7 +62,15 @@ var DaemonCmd = &cobra.Command{
}()
for _, svc := range cfg.Service {
log.Info("Processing service", "name", svc.Name, "enabled", svc.Enabled, "path", svc.LogPath)
log.Info(
"Processing service",
"name",
svc.Name,
"enabled",
svc.Enabled,
"path",
svc.LogPath,
)
if !svc.Enabled {
log.Info("Service disabled, skipping", "name", svc.Name)

View File

@@ -60,7 +60,14 @@ var ListCmd = &cobra.Command{
os.Exit(1)
}
for _, rule := range r {
fmt.Printf("Name: %s\nService: %s\nPath: %s\nStatus: %s\nMethod: %s\n\n", rule.Name, rule.ServiceName, rule.Path, rule.Status, rule.Method)
fmt.Printf(
"Name: %s\nService: %s\nPath: %s\nStatus: %s\nMethod: %s\n\n",
rule.Name,
rule.ServiceName,
rule.Path,
rule.Status,
rule.Method,
)
}
},
}

View File

@@ -25,7 +25,14 @@ func LoadRuleConfig() ([]Rule, error) {
return cfg.Rules, nil
}
func NewRule(Name string, ServiceName string, Path string, Status string, Method string, ttl string) error {
func NewRule(
Name string,
ServiceName string,
Path string,
Status string,
Method string,
ttl string,
) error {
r, err := LoadRuleConfig()
if err != nil {
r = []Rule{}
@@ -34,7 +41,17 @@ func NewRule(Name string, ServiceName string, Path string, Status string, Method
fmt.Printf("Rule name can't be empty\n")
return nil
}
r = append(r, Rule{Name: Name, ServiceName: ServiceName, Path: Path, Status: Status, Method: Method, BanTime: ttl})
r = append(
r,
Rule{
Name: Name,
ServiceName: ServiceName,
Path: Path,
Status: Status,
Method: Method,
BanTime: ttl,
},
)
file, err := os.Create("/etc/banforge/rules.toml")
if err != nil {
return err

View File

@@ -51,7 +51,16 @@ func (j *Judge) ProcessUnviewed() error {
}()
for rows.Next() {
var entry storage.LogEntry
err = rows.Scan(&entry.ID, &entry.Service, &entry.IP, &entry.Path, &entry.Status, &entry.Method, &entry.IsViewed, &entry.CreatedAt)
err = rows.Scan(
&entry.ID,
&entry.Service,
&entry.IP,
&entry.Path,
&entry.Status,
&entry.Method,
&entry.IsViewed,
&entry.CreatedAt,
)
if err != nil {
j.logger.Error(fmt.Sprintf("Failed to scan database row: %v", err))
continue
@@ -64,7 +73,13 @@ func (j *Judge) ProcessUnviewed() error {
(rule.Status == "" || entry.Status == rule.Status) &&
(rule.Path == "" || entry.Path == rule.Path) {
j.logger.Info(fmt.Sprintf("Rule matched for IP: %s, Service: %s", entry.IP, entry.Service))
j.logger.Info(
fmt.Sprintf(
"Rule matched for IP: %s, Service: %s",
entry.IP,
entry.Service,
),
)
ban_status, err := j.db.IsBanned(entry.IP)
if err != nil {
j.logger.Error(fmt.Sprintf("Failed to check ban status: %v", err))

View File

@@ -42,7 +42,17 @@ func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEn
Method: method,
IsViewed: false,
}
p.logger.Info("Parsed nginx log entry", "ip", matches[1], "path", path, "status", status, "method", method)
p.logger.Info(
"Parsed nginx log entry",
"ip",
matches[1],
"path",
path,
"status",
status,
"method",
method,
)
}
}()
}

View File

@@ -22,7 +22,9 @@ type Scanner struct {
}
func NewScanner(path string) (*Scanner, error) {
file, err := os.Open(path) // #nosec G304 -- admin tool, runs as root, path controlled by operator
file, err := os.Open(
path,
) // #nosec G304 -- admin tool, runs as root, path controlled by operator
if err != nil {
return nil, err
}

View File

@@ -19,7 +19,10 @@ type DB struct {
}
func NewDB() (*DB, error) {
db, err := sql.Open("sqlite3", "/var/lib/banforge/storage.db?mode=rwc&_journal_mode=WAL&_busy_timeout=10000&cache=shared")
db, err := sql.Open(
"sqlite3",
"/var/lib/banforge/storage.db?mode=rwc&_journal_mode=WAL&_busy_timeout=10000&cache=shared",
)
if err != nil {
return nil, err
}
@@ -52,7 +55,9 @@ func (d *DB) CreateTable() error {
}
func (d *DB) SearchUnViewed() (*sql.Rows, error) {
rows, err := d.db.Query("SELECT id, service, ip, path, status, method, viewed, created_at FROM requests WHERE viewed = 0")
rows, err := d.db.Query(
"SELECT id, service, ip, path, status, method, viewed, created_at FROM requests WHERE viewed = 0",
)
if err != nil {
d.logger.Error("Failed to query database")
return nil, err
@@ -136,7 +141,10 @@ func (d *DB) BanList() error {
func (d *DB) CheckExpiredBans() ([]string, error) {
var ips []string
rows, err := d.db.Query("SELECT ip FROM bans WHERE expired_at < ?", time.Now().Format(time.RFC3339))
rows, err := d.db.Query(
"SELECT ip FROM bans WHERE expired_at < ?",
time.Now().Format(time.RFC3339),
)
if err != nil {
d.logger.Error("Failed to get ban list", "error", err)
return nil, err