Files
bssapp/svc/internal/auditlog/helpers.go
2026-02-11 17:46:22 +03:00

74 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package auditlog
import (
"crypto/md5"
"fmt"
"time"
)
//
// =======================================================
// 🕵️ AUDIT LOG — HELPER FUNCTIONS
// =======================================================
// Bu dosya:
// - UUID bekleyen kolonlar için int → uuid dönüşümü
// - NULL-safe insert yardımcıları
// içerir
//
// -------------------------------------------------------
// 🔹 IntUserIDToUUID
// -------------------------------------------------------
// int user_id → deterministic UUID
// PostgreSQL uuid kolonu ile %100 uyumlu
//
// Aynı userID → her zaman aynı UUID
func IntUserIDToUUID(userID int) string {
if userID <= 0 {
return ""
}
sum := md5.Sum([]byte(fmt.Sprintf("bssapp-user-%d", userID)))
return fmt.Sprintf(
"%x-%x-%x-%x-%x",
sum[0:4],
sum[4:6],
sum[6:8],
sum[8:10],
sum[10:16],
)
}
// -------------------------------------------------------
// 🔹 nullIfZeroTime
// -------------------------------------------------------
// Zero time → NULL (SQL uyumlu)
func nullIfZeroTime(t time.Time) interface{} {
if t.IsZero() {
return nil
}
return t
}
// -------------------------------------------------------
// 🔹 nullIfZeroInt
// -------------------------------------------------------
// 0 → NULL (SQL uyumlu)
func nullIfZeroInt(v int) interface{} {
if v == 0 {
return nil
}
return v
}
func Int64UserIDToUUID(id int64) string {
return IntUserIDToUUID(int(id))
}
func nullIfEmpty(s string) any {
if s == "" {
return nil
}
return s
}