feat: implement new generic parser and improve production readyness

This commit is contained in:
Patryk Hegenberg 2026-01-18 12:37:57 +01:00
parent 8364218234
commit 0830b403e0
34 changed files with 1715 additions and 2114 deletions

View file

@ -3,11 +3,10 @@ package helpers
import (
"fmt"
"log/slog"
"os"
"regexp"
"strings"
"time"
"tixel_watch/models"
"watch-tool/models"
)
var (
@ -76,11 +75,3 @@ func ParseSyslogTimeToRFC3339(syslogTime string) (time.Time, error) {
t = t.AddDate(now.Year(), 0, 0)
return t, nil
}
func GetHostname() (string, error) {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknown"
}
return hostname, nil
}

47
helpers/utils.go Normal file
View file

@ -0,0 +1,47 @@
package helpers
import (
"context"
"fmt"
"log/slog"
"runtime/debug"
)
type AppError struct {
Op string
Err error
Context string
}
func (e *AppError) Error() string {
if e.Context != "" {
return fmt.Sprintf("%s: %v (%s)", e.Op, e.Err, e.Context)
}
return fmt.Sprintf("%s: %v", e.Op, e.Err)
}
func (e *AppError) Unwrap() error {
return e.Err
}
func NewAppError(op string, err error, ctx string) error {
return &AppError{Op: op, Err: err, Context: ctx}
}
func SafeGo(ctx context.Context, name string, fn func()) {
go func() {
defer func() {
if r := recover(); r != nil {
stack := string(debug.Stack())
slog.Error("CRITICAL: Panic recovered in goroutine",
"goroutine", name,
"panic", r,
"stack", stack,
)
// Optional: Hier könnte man Metriken inkrementieren (siehe Observability)
}
}()
fn()
}()
}