From de000ab5b6047b35740f0ff3067ed6358ea50a1b Mon Sep 17 00:00:00 2001 From: d3m0k1d Date: Wed, 21 Jan 2026 21:40:57 +0300 Subject: [PATCH] fix: fix Nginx parser start without gourutine --- internal/parser/NginxParser.go | 58 ++++++++++++++++------------------ internal/storage/writer.go | 1 + 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/internal/parser/NginxParser.go b/internal/parser/NginxParser.go index f4c6541..3e15b19 100644 --- a/internal/parser/NginxParser.go +++ b/internal/parser/NginxParser.go @@ -24,35 +24,33 @@ func NewNginxParser() *NginxParser { func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEntry) { // Group 1: IP, Group 2: Timestamp, Group 3: Method, Group 4: Path, Group 5: Status - go func() { - for event := range eventCh { - matches := p.pattern.FindStringSubmatch(event.Data) - if matches == nil { - continue - } - path := matches[4] - status := matches[5] - method := matches[3] - - resultCh <- &storage.LogEntry{ - Service: "nginx", - IP: matches[1], - Path: path, - Status: status, - Method: method, - IsViewed: false, - } - p.logger.Info( - "Parsed nginx log entry", - "ip", - matches[1], - "path", - path, - "status", - status, - "method", - method, - ) + for event := range eventCh { + matches := p.pattern.FindStringSubmatch(event.Data) + if matches == nil { + continue } - }() + path := matches[4] + status := matches[5] + method := matches[3] + + resultCh <- &storage.LogEntry{ + Service: "nginx", + IP: matches[1], + Path: path, + Status: status, + Method: method, + IsViewed: false, + } + p.logger.Info( + "Parsed nginx log entry", + "ip", + matches[1], + "path", + path, + "status", + status, + "method", + method, + ) + } } diff --git a/internal/storage/writer.go b/internal/storage/writer.go index dc03e08..ae67a16 100644 --- a/internal/storage/writer.go +++ b/internal/storage/writer.go @@ -5,6 +5,7 @@ import ( ) func Write(db *DB, resultCh <-chan *LogEntry) { + db.logger.Info("Starting log writer") const batchSize = 100 const flushInterval = 1 * time.Second