Files
goplt/internal/ent/auditlog.go
0x1d 30320304f6 feat(epic1): implement core infrastructure (stories 1.1-1.5)
Implemented Epic 1 core kernel and infrastructure stories:

Story 1.1: Enhanced DI Container
- Added providers for database, health, metrics, and error bus
- Extended CoreModule to include all core services

Story 1.2: Database Layer with Ent ORM
- Created Ent schema for User, Role, Permission, AuditLog entities
- Implemented many-to-many relationships (User-Role, Role-Permission)
- Created database client wrapper with connection pooling
- Added database provider to DI container with migration support

Story 1.3: Health Monitoring and Metrics System
- Implemented health check registry and interface
- Added database health checker
- Created Prometheus metrics system with HTTP instrumentation
- Added health and metrics providers to DI container

Story 1.4: Error Handling and Error Bus
- Implemented channel-based error bus
- Created ErrorPublisher interface
- Added error bus provider with lifecycle management

Story 1.5: HTTP Server Foundation
- Created HTTP server with Gin framework
- Implemented comprehensive middleware stack:
  - Request ID generation
  - Structured logging
  - Panic recovery with error bus integration
  - Prometheus metrics collection
  - CORS support
- Registered core routes: /healthz, /ready, /metrics
- Integrated with FX lifecycle for graceful shutdown

All components are integrated via DI container and ready for use.
2025-11-05 18:11:11 +01:00

154 lines
4.9 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"git.dcentral.systems/toolz/goplt/internal/ent/auditlog"
)
// AuditLog is the model entity for the AuditLog schema.
type AuditLog struct {
config `json:"-"`
// ID of the ent.
ID string `json:"id,omitempty"`
// ID of the user/actor performing the action
ActorID string `json:"actor_id,omitempty"`
// Action performed (e.g., create, update, delete)
Action string `json:"action,omitempty"`
// ID of the target resource
TargetID string `json:"target_id,omitempty"`
// Additional metadata as JSON
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Timestamp holds the value of the "timestamp" field.
Timestamp time.Time `json:"timestamp,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*AuditLog) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case auditlog.FieldMetadata:
values[i] = new([]byte)
case auditlog.FieldID, auditlog.FieldActorID, auditlog.FieldAction, auditlog.FieldTargetID:
values[i] = new(sql.NullString)
case auditlog.FieldTimestamp:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the AuditLog fields.
func (_m *AuditLog) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case auditlog.FieldID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value.Valid {
_m.ID = value.String
}
case auditlog.FieldActorID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field actor_id", values[i])
} else if value.Valid {
_m.ActorID = value.String
}
case auditlog.FieldAction:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field action", values[i])
} else if value.Valid {
_m.Action = value.String
}
case auditlog.FieldTargetID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field target_id", values[i])
} else if value.Valid {
_m.TargetID = value.String
}
case auditlog.FieldMetadata:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field metadata", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Metadata); err != nil {
return fmt.Errorf("unmarshal field metadata: %w", err)
}
}
case auditlog.FieldTimestamp:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field timestamp", values[i])
} else if value.Valid {
_m.Timestamp = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the AuditLog.
// This includes values selected through modifiers, order, etc.
func (_m *AuditLog) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this AuditLog.
// Note that you need to call AuditLog.Unwrap() before calling this method if this AuditLog
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *AuditLog) Update() *AuditLogUpdateOne {
return NewAuditLogClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the AuditLog entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *AuditLog) Unwrap() *AuditLog {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: AuditLog is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *AuditLog) String() string {
var builder strings.Builder
builder.WriteString("AuditLog(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("actor_id=")
builder.WriteString(_m.ActorID)
builder.WriteString(", ")
builder.WriteString("action=")
builder.WriteString(_m.Action)
builder.WriteString(", ")
builder.WriteString("target_id=")
builder.WriteString(_m.TargetID)
builder.WriteString(", ")
builder.WriteString("metadata=")
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
builder.WriteString(", ")
builder.WriteString("timestamp=")
builder.WriteString(_m.Timestamp.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// AuditLogs is a parsable slice of AuditLog.
type AuditLogs []*AuditLog