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.
This commit is contained in:
2025-11-05 18:11:11 +01:00
parent a38a08ca17
commit 30320304f6
77 changed files with 19409 additions and 30 deletions

View File

@@ -0,0 +1,182 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"git.dcentral.systems/toolz/goplt/internal/ent/permission"
"git.dcentral.systems/toolz/goplt/internal/ent/role"
"git.dcentral.systems/toolz/goplt/internal/ent/rolepermission"
)
// RolePermission is the model entity for the RolePermission schema.
type RolePermission struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// RoleID holds the value of the "role_id" field.
RoleID string `json:"role_id,omitempty"`
// PermissionID holds the value of the "permission_id" field.
PermissionID string `json:"permission_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the RolePermissionQuery when eager-loading is set.
Edges RolePermissionEdges `json:"edges"`
permission_role_permissions *string
role_role_permissions *string
selectValues sql.SelectValues
}
// RolePermissionEdges holds the relations/edges for other nodes in the graph.
type RolePermissionEdges struct {
// Role holds the value of the role edge.
Role *Role `json:"role,omitempty"`
// Permission holds the value of the permission edge.
Permission *Permission `json:"permission,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// RoleOrErr returns the Role value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RolePermissionEdges) RoleOrErr() (*Role, error) {
if e.Role != nil {
return e.Role, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: role.Label}
}
return nil, &NotLoadedError{edge: "role"}
}
// PermissionOrErr returns the Permission value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RolePermissionEdges) PermissionOrErr() (*Permission, error) {
if e.Permission != nil {
return e.Permission, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: permission.Label}
}
return nil, &NotLoadedError{edge: "permission"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*RolePermission) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case rolepermission.FieldID:
values[i] = new(sql.NullInt64)
case rolepermission.FieldRoleID, rolepermission.FieldPermissionID:
values[i] = new(sql.NullString)
case rolepermission.ForeignKeys[0]: // permission_role_permissions
values[i] = new(sql.NullString)
case rolepermission.ForeignKeys[1]: // role_role_permissions
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the RolePermission fields.
func (_m *RolePermission) 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 rolepermission.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int(value.Int64)
case rolepermission.FieldRoleID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field role_id", values[i])
} else if value.Valid {
_m.RoleID = value.String
}
case rolepermission.FieldPermissionID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field permission_id", values[i])
} else if value.Valid {
_m.PermissionID = value.String
}
case rolepermission.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field permission_role_permissions", values[i])
} else if value.Valid {
_m.permission_role_permissions = new(string)
*_m.permission_role_permissions = value.String
}
case rolepermission.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field role_role_permissions", values[i])
} else if value.Valid {
_m.role_role_permissions = new(string)
*_m.role_role_permissions = value.String
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the RolePermission.
// This includes values selected through modifiers, order, etc.
func (_m *RolePermission) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryRole queries the "role" edge of the RolePermission entity.
func (_m *RolePermission) QueryRole() *RoleQuery {
return NewRolePermissionClient(_m.config).QueryRole(_m)
}
// QueryPermission queries the "permission" edge of the RolePermission entity.
func (_m *RolePermission) QueryPermission() *PermissionQuery {
return NewRolePermissionClient(_m.config).QueryPermission(_m)
}
// Update returns a builder for updating this RolePermission.
// Note that you need to call RolePermission.Unwrap() before calling this method if this RolePermission
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *RolePermission) Update() *RolePermissionUpdateOne {
return NewRolePermissionClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the RolePermission 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 *RolePermission) Unwrap() *RolePermission {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: RolePermission is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *RolePermission) String() string {
var builder strings.Builder
builder.WriteString("RolePermission(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("role_id=")
builder.WriteString(_m.RoleID)
builder.WriteString(", ")
builder.WriteString("permission_id=")
builder.WriteString(_m.PermissionID)
builder.WriteByte(')')
return builder.String()
}
// RolePermissions is a parsable slice of RolePermission.
type RolePermissions []*RolePermission