infrastructure

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package infrastructure provides core infrastructure components and their dependency injection setup. This package serves as the foundation for the application's infrastructure layer, managing database connections, logging, event systems, and web server configuration.

Index

Constants

View Source
const (
	// MinSecretLength is the minimum length required for security secrets
	MinSecretLength = 32

	// DefaultLogLevel is the default log level for production
	DefaultLogLevel = "info"
	// DevelopmentLogLevel is the default log level for development
	DevelopmentLogLevel = "debug"
	// ProductionLogLevel is the log level for production
	ProductionLogLevel = "warn"
)

Variables

View Source
var (
	// ErrMissingLogger is returned when a required logger dependency is nil
	ErrMissingLogger = errors.New("logger is required")

	// ErrMissingConfig is returned when a required config dependency is nil
	ErrMissingConfig = errors.New("config is required")

	// ErrInvalidLogLevel is returned when an invalid log level is specified
	ErrInvalidLogLevel = errors.New("invalid log level specified")

	// ErrMissingSanitizer is returned when a required sanitizer dependency is nil
	ErrMissingSanitizer = errors.New("sanitizer is required for logger factory")
)
View Source
var Module = fx.Module("infrastructure",

	fx.Provide(

		ProvideEcho,

		ProvideDatabase,

		server.New,

		fx.Annotate(
			ProvideSanitizationService,
			fx.As(new(sanitization.ServiceInterface)),
		),

		NewLoggerFactory,
		NewLogger,

		NewEventPublisher,
		event.NewMemoryEventBus,

		fx.Annotate(
			ProvideAssetServer,
			fx.As(new(infraweb.AssetServer)),
		),
		fx.Annotate(
			NewAssetManager,
			fx.As(new(infraweb.AssetManagerInterface)),
		),
	),

	fx.Invoke(func(lc fx.Lifecycle, logger logging.Logger, _ *config.Config) {
		lc.Append(fx.Hook{
			OnStart: func(_ context.Context) error {
				logger.Info("Infrastructure module initialized")

				return nil
			},
			OnStop: func(_ context.Context) error {
				logger.Info("Infrastructure module shutting down")

				return nil
			},
		})
	}),
)

Module provides comprehensive infrastructure dependencies with proper error handling, lifecycle management, and clear separation of concerns.

Functions

func AnnotateHandler

func AnnotateHandler(fn any) fx.Option

AnnotateHandler is a helper function that simplifies the creation of handler providers. It automatically registers handlers with the appropriate fx annotations and grouping.

func NewAssetManager added in v0.1.5

NewAssetManager creates a new asset manager with proper dependency validation. Returns the interface type for better dependency injection.

func NewEventPublisher added in v0.1.5

func NewEventPublisher(p EventPublisherParams) (formevent.Publisher, error)

NewEventPublisher creates a new event publisher with proper dependency validation. It returns an error if required dependencies are missing or invalid.

func NewLogger added in v0.1.5

func NewLogger(factory *logging.Factory) (logging.Logger, error)

NewLogger creates a logger instance from the factory with proper error handling.

func NewLoggerFactory added in v0.1.5

func NewLoggerFactory(p LoggerFactoryParams) (*logging.Factory, error)

NewLoggerFactory creates a new logger factory with proper configuration and error handling.

func ProvideAssetServer added in v0.1.5

func ProvideAssetServer(p AssetServerParams) (infraweb.AssetServer, error)

ProvideAssetServer creates an appropriate asset server based on the environment. In development, it serves static files from public directory while Vite handles JS/CSS. In production, it serves from embedded filesystem for optimal performance.

func ProvideDatabase added in v0.1.5

func ProvideDatabase(lc fx.Lifecycle, cfg *config.Config, logger logging.Logger) (database.DB, error)

ProvideDatabase creates a new database connection with lifecycle management.

func ProvideEcho added in v0.1.5

func ProvideEcho() *echo.Echo

ProvideEcho creates and configures a new Echo instance with sensible defaults.

func ProvideSanitizationService added in v0.1.5

func ProvideSanitizationService() sanitization.ServiceInterface

ProvideSanitizationService creates a new sanitization service with proper annotations.

Types

type AssetManagerParams added in v0.1.5

type AssetManagerParams struct {
	fx.In
	DistFS embed.FS
	Logger logging.Logger `validate:"required"`
	Config *config.Config `validate:"required"`
}

AssetManagerParams contains dependencies for creating an asset manager

type AssetServerParams added in v0.1.5

type AssetServerParams struct {
	fx.In
	Config *config.Config `validate:"required"`
	Logger logging.Logger `validate:"required"`
	DistFS embed.FS
}

AssetServerParams groups the dependencies for creating an asset server. The asset server handles static file serving with environment-specific optimizations.

type CoreParams

type CoreParams struct {
	fx.In
	Config   *config.Config `validate:"required"`
	Logger   logging.Logger `validate:"required"`
	Renderer view.Renderer  `validate:"required"`
	Echo     *echo.Echo     `validate:"required"`
}

CoreParams groups core infrastructure dependencies required for basic application functionality. These dependencies form the foundation of the application's runtime environment.

func (CoreParams) Validate added in v0.1.5

func (p CoreParams) Validate() error

Validate ensures all required core parameters are present

type EventPublisherParams added in v0.1.5

type EventPublisherParams struct {
	fx.In
	Logger logging.Logger `validate:"required"`
}

EventPublisherParams contains dependencies for creating an event publisher. The event publisher is responsible for distributing domain events throughout the application.

type LoggerFactoryParams added in v0.1.5

type LoggerFactoryParams struct {
	fx.In
	Config    *config.Config                `validate:"required"`
	Sanitizer sanitization.ServiceInterface `validate:"required"`
}

LoggerFactoryParams contains dependencies for creating a logger factory

type ServiceParams

type ServiceParams struct {
	fx.In
	UserService user.Service `validate:"required"`
	FormService form.Service `validate:"required"`
}

ServiceParams groups business service dependencies. These represent the core business logic services of the application.

func (ServiceParams) Validate added in v0.1.5

func (p ServiceParams) Validate() error

Validate ensures all required service parameters are present

Directories

Path Synopsis
Package config provides configuration management for the GoForms application.
Package config provides configuration management for the GoForms application.
Package database provides database connection and ORM utilities for the application.
Package database provides database connection and ORM utilities for the application.
Package event provides in-memory event bus and publisher implementations.
Package event provides in-memory event bus and publisher implementations.
Package logging provides a unified logging interface
Package logging provides a unified logging interface
Package metrics provides application metrics collection and reporting functionality for monitoring application performance and health.
Package metrics provides application metrics collection and reporting functionality for monitoring application performance and health.
Package middleware provides infrastructure layer middleware adapters for integrating framework-agnostic middleware with specific HTTP frameworks.
Package middleware provides infrastructure layer middleware adapters for integrating framework-agnostic middleware with specific HTTP frameworks.
repository
common
Package common provides shared utilities and types for repository implementations including error handling, pagination, and common data structures.
Package common provides shared utilities and types for repository implementations including error handling, pagination, and common data structures.
form
Package repository provides the form repository implementation
Package repository provides the form repository implementation
form/submission
Package repository provides the form submission repository implementation
Package repository provides the form submission repository implementation
user
Package repository provides the user repository implementation
Package repository provides the user repository implementation
Package sanitization provides utilities for cleaning and validating user input to prevent XSS attacks, injection attacks, and other security vulnerabilities.
Package sanitization provides utilities for cleaning and validating user input to prevent XSS attacks, injection attacks, and other security vulnerabilities.
Package server provides HTTP server setup and lifecycle management for the application.
Package server provides HTTP server setup and lifecycle management for the application.
Package validation provides infrastructure-level validation utilities and interfaces.
Package validation provides infrastructure-level validation utilities and interfaces.
Package version provides version information for the application.
Package version provides version information for the application.
Package web provides utilities for handling web assets in the application.
Package web provides utilities for handling web assets in the application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL