Documentation
¶
Index ¶
- Constants
- func GeneratePDF(cfg *config.Config, template config.Template) ([]byte, map[string]string, error)
- func NewLoggerAdapter(logger Logger) autopdfports.Logger
- type ErrorDetails
- func (ed *ErrorDetails) AddContext(key, value string) *ErrorDetails
- func (ed *ErrorDetails) LogError(logger *logger.LoggerAdapter) *ErrorDetails
- func (ed *ErrorDetails) LogErrorWithMessage(logger *logger.LoggerAdapter, message string) *ErrorDetails
- func (ed *ErrorDetails) ToMap() map[string]interface{}
- func (ed *ErrorDetails) WithEngine(engine string) *ErrorDetails
- func (ed *ErrorDetails) WithError(err error) *ErrorDetails
- func (ed *ErrorDetails) WithFilePath(path string) *ErrorDetails
- func (ed *ErrorDetails) WithFileSize(size int64) *ErrorDetails
- func (ed *ErrorDetails) WithFormat(format string) *ErrorDetails
- func (ed *ErrorDetails) WithOutputPath(path string) *ErrorDetails
- func (ed *ErrorDetails) WithPageCount(count int) *ErrorDetails
- func (ed *ErrorDetails) WithRecovery(suggestions []string, retryable bool, maxRetries int, timeout time.Duration) *ErrorDetails
- func (ed *ErrorDetails) WithSystem(os, arch string, memory, diskSpace int64, processID int) *ErrorDetails
- func (ed *ErrorDetails) WithTemplatePath(path string) *ErrorDetails
- func (ed *ErrorDetails) WithValidation(rule string, expected, actual interface{}) *ErrorDetails
- type LogField
- type Logger
- type LoggerAdapter
- func (a *LoggerAdapter) Debug(ctx context.Context, msg string, fields ...autopdfports.LogField)
- func (a *LoggerAdapter) Error(ctx context.Context, msg string, fields ...autopdfports.LogField)
- func (a *LoggerAdapter) Info(ctx context.Context, msg string, fields ...autopdfports.LogField)
- func (a *LoggerAdapter) Warn(ctx context.Context, msg string, fields ...autopdfports.LogField)
- type NoOpLoggerAdapter
- func (n *NoOpLoggerAdapter) Debug(ctx context.Context, msg string, fields ...autopdfports.LogField)
- func (n *NoOpLoggerAdapter) Error(ctx context.Context, msg string, fields ...autopdfports.LogField)
- func (n *NoOpLoggerAdapter) Info(ctx context.Context, msg string, fields ...autopdfports.LogField)
- func (n *NoOpLoggerAdapter) Warn(ctx context.Context, msg string, fields ...autopdfports.LogField)
- type RecoveryDetails
- type SystemDetails
- type ValidationDetails
- type ValidationUtils
- func (vu *ValidationUtils) CreateRecoverySuggestions(category, errorCode string) []string
- func (vu *ValidationUtils) GetFileMetadata(filePath string) (map[string]interface{}, error)
- func (vu *ValidationUtils) ValidateEngine(engine string) (*ErrorDetails, error)
- func (vu *ValidationUtils) ValidateOutputPath(outputPath string) (*ErrorDetails, error)
- func (vu *ValidationUtils) ValidatePDFContent(pdfPath string) (*ErrorDetails, error)
- func (vu *ValidationUtils) ValidatePDFPath(pdfPath string) (*ErrorDetails, error)
- func (vu *ValidationUtils) ValidateTemplatePath(templatePath string) (*ErrorDetails, error)
Constants ¶
const ( // PDF Path validation ErrPDFPathRequired = "PDF path is required" ErrPDFPathEmpty = "PDF path cannot be empty" ErrPDFPathInvalid = "Invalid PDF path format" // PDF File validation ErrPDFFileNotFound = "PDF file does not exist: %s" ErrPDFFileNotReadable = "Cannot read PDF file: %s" ErrPDFFileEmpty = "PDF file is empty: %s" ErrPDFFileInvalid = "File is not a valid PDF: %s" ErrPDFFileCorrupted = "PDF file appears to be corrupted: %s" ErrPDFFileExtensionInvalid = "File does not have .pdf extension: %s" // PDF Structure validation ErrPDFHeaderInvalid = "Invalid PDF header signature" ErrPDFStructureInvalid = "Invalid PDF structure" ErrPDFVersionInvalid = "Unsupported PDF version" ErrPDFValidationFailed = "PDF validation failed" // PDF Metadata validation ErrPDFMetadataInvalid = "Cannot extract PDF metadata: %s" ErrPDFPageCountInvalid = "Cannot determine page count: %s" ErrPDFFileSizeInvalid = "Cannot determine file size: %s" // PDF Content validation ErrPDFContentInvalid = "PDF content validation failed: %s" ErrPDFSecurityInvalid = "PDF security validation failed: %s" )
PDF Validation Error Messages
const ( // Template Path validation ErrTemplatePathRequired = "Template path is required" ErrTemplatePathEmpty = "Template path cannot be empty" ErrTemplatePathInvalid = "Invalid template path format" // Template File validation ErrTemplateFileNotFound = "Template file does not exist: %s" ErrTemplateFileNotReadable = "Cannot read template file: %s" ErrTemplateFileEmpty = "Template file is empty: %s" ErrTemplateFileInvalid = "Template file is not a valid LaTeX file: %s" // Template Content validation ErrTemplateContentInvalid = "Template content validation failed: %s" ErrTemplateSyntaxInvalid = "Template contains invalid LaTeX syntax: %s" ErrTemplateVariablesInvalid = "Template variables validation failed: %s" ErrTemplateDelimitersInvalid = "Template delimiters validation failed: %s" // Template Processing validation ErrTemplateProcessingFailed = "Template processing failed: %s" ErrTemplateRenderingFailed = "Template rendering failed: %s" ErrTemplateCompilationFailed = "Template compilation failed: %s" ErrTemplateValidationFailed = "Template validation failed: %s" )
Template Processing Error Messages
const ( // Variable validation ErrVariableKeyRequired = "Variable key is required" ErrVariableKeyEmpty = "Variable key cannot be empty" ErrVariableKeyInvalid = "Invalid variable key format: %s" ErrVariableValueInvalid = "Invalid variable value: %s" ErrVariableTypeInvalid = "Unsupported variable type: %s" // Variable resolution ErrVariableResolutionFailed = "Variable resolution failed: %s" ErrVariableFlatteningFailed = "Variable flattening failed: %s" ErrVariableValidationFailed = "Variable validation failed: %s" )
Variable Resolution Error Messages
const ( // Generation process ErrPDFGenerationFailed = "PDF generation failed: %s" ErrPDFGenerationTimeout = "PDF generation timeout: %s" ErrPDFGenerationCancelled = "PDF generation cancelled: %s" // Engine validation ErrEngineRequired = "LaTeX engine is required" ErrEngineNotFound = "LaTeX engine not found: %s" ErrEngineNotSupported = "Unsupported LaTeX engine: %s" ErrEngineExecutionFailed = "LaTeX engine execution failed: %s" // Output validation ErrOutputPathRequired = "Output path is required" ErrOutputPathInvalid = "Invalid output path: %s" ErrOutputPathNotWritable = "Cannot write to output path: %s" ErrOutputPathExists = "Output file already exists: %s" // Conversion validation ErrConversionFailed = "PDF conversion failed: %s" ErrConversionFormatInvalid = "Unsupported conversion format: %s" ErrConversionTimeout = "Conversion timeout: %s" )
PDF Generation Error Messages
const ( // File system errors ErrFileSystemAccess = "File system access error: %s" ErrFileSystemPermission = "File system permission error: %s" ErrFileSystemSpace = "Insufficient disk space: %s" // Memory errors ErrMemoryAllocation = "Memory allocation failed: %s" ErrMemoryInsufficient = "Insufficient memory: %s" // Network errors ErrNetworkConnection = "Network connection error: %s" ErrNetworkTimeout = "Network timeout: %s" )
System Error Messages
const ( ErrorCategoryPDF = "pdf_validation" ErrorCategoryTemplate = "template_processing" ErrorCategoryVariable = "variable_resolution" ErrorCategoryGeneration = "pdf_generation" ErrorCategoryConfiguration = "configuration" ErrorCategorySystem = "system" ErrorCategoryNetwork = "network" ErrorCategoryFileSystem = "file_system" )
Error Categories
const ( ErrorSeverityLow = "low" ErrorSeverityMedium = "medium" ErrorSeverityHigh = "high" ErrorSeverityCritical = "critical" )
Error Severity Levels
const ( ContextKeyPDFPath = "pdf_path" ContextKeyTemplatePath = "template_path" ContextKeyOutputPath = "output_path" ContextKeyEngine = "engine" ContextKeyFormat = "format" ContextKeyError = "error" ContextKeyTimestamp = "timestamp" ContextKeyDuration = "duration" ContextKeyFileSize = "file_size" ContextKeyPageCount = "page_count" )
Error Context Keys
const ( // PDF validation rules MinPDFFileSize = 100 // Minimum PDF file size in bytes MaxPDFFileSize = 100 * 1024 * 1024 // Maximum PDF file size (100MB) MinPDFHeaderLength = 4 // Minimum PDF header length // Template validation rules MinTemplateFileSize = 50 // Minimum template file size in bytes MaxTemplateFileSize = 10 * 1024 * 1024 // Maximum template file size (10MB) // Variable validation rules MaxVariableKeyLength = 100 // Maximum variable key length MaxVariableValueLength = 10000 // Maximum variable value length MaxVariableCount = 1000 // Maximum number of variables )
Validation Rules
const ( // PDF defaults DefaultPDFVersion = "1.4" DefaultPDFPageCount = 1 DefaultPDFFileSize = 1024 // Template defaults DefaultTemplateEngine = "pdflatex" DefaultTemplateFormat = "tex" // Validation defaults DefaultValidationTimeout = "30s" DefaultValidationRetries = 3 )
Default Values
Variables ¶
This section is empty.
Functions ¶
func GeneratePDF ¶
GeneratePDF generates a PDF using the internal application layer This function maintains the same signature while using the adapter pattern
func NewLoggerAdapter ¶ added in v1.3.0
func NewLoggerAdapter(logger Logger) autopdfports.Logger
NewLoggerAdapter creates a new adapter from a public Logger
Types ¶
type ErrorDetails ¶ added in v1.2.0
type ErrorDetails struct {
// Core identification
Category string `json:"category"`
Severity string `json:"severity"`
Timestamp time.Time `json:"timestamp"`
// Context information
Context map[string]string `json:"context,omitempty"`
// File information
FilePath string `json:"file_path,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
FileExists bool `json:"file_exists,omitempty"`
// Validation information
Validation *ValidationDetails `json:"validation,omitempty"`
// System information
System *SystemDetails `json:"system,omitempty"`
// Recovery information
Recovery *RecoveryDetails `json:"recovery,omitempty"`
}
ErrorDetails represents structured error information This replaces the generic map[string]interface{} with a proper entity
func NewErrorDetails ¶ added in v1.2.0
func NewErrorDetails(category, severity string) *ErrorDetails
NewErrorDetails creates a new ErrorDetails with default values
func (*ErrorDetails) AddContext ¶ added in v1.2.0
func (ed *ErrorDetails) AddContext(key, value string) *ErrorDetails
AddContext adds a key-value pair to the context
func (*ErrorDetails) LogError ¶ added in v1.2.2
func (ed *ErrorDetails) LogError(logger *logger.LoggerAdapter) *ErrorDetails
LogError logs the error details using structured logging
func (*ErrorDetails) LogErrorWithMessage ¶ added in v1.2.2
func (ed *ErrorDetails) LogErrorWithMessage(logger *logger.LoggerAdapter, message string) *ErrorDetails
LogErrorWithMessage logs the error details with a custom message
func (*ErrorDetails) ToMap ¶ added in v1.2.0
func (ed *ErrorDetails) ToMap() map[string]interface{}
ToMap converts ErrorDetails to a map for backward compatibility
func (*ErrorDetails) WithEngine ¶ added in v1.2.0
func (ed *ErrorDetails) WithEngine(engine string) *ErrorDetails
WithEngine adds engine information to the error details
func (*ErrorDetails) WithError ¶ added in v1.2.0
func (ed *ErrorDetails) WithError(err error) *ErrorDetails
WithError adds error information to the error details
func (*ErrorDetails) WithFilePath ¶ added in v1.2.0
func (ed *ErrorDetails) WithFilePath(path string) *ErrorDetails
WithFilePath adds file path information to the error details
func (*ErrorDetails) WithFileSize ¶ added in v1.2.0
func (ed *ErrorDetails) WithFileSize(size int64) *ErrorDetails
WithFileSize adds file size information to the error details
func (*ErrorDetails) WithFormat ¶ added in v1.2.0
func (ed *ErrorDetails) WithFormat(format string) *ErrorDetails
WithFormat adds format information to the error details
func (*ErrorDetails) WithOutputPath ¶ added in v1.2.0
func (ed *ErrorDetails) WithOutputPath(path string) *ErrorDetails
WithOutputPath adds output path information to the error details
func (*ErrorDetails) WithPageCount ¶ added in v1.2.0
func (ed *ErrorDetails) WithPageCount(count int) *ErrorDetails
WithPageCount adds page count information to the error details
func (*ErrorDetails) WithRecovery ¶ added in v1.2.0
func (ed *ErrorDetails) WithRecovery(suggestions []string, retryable bool, maxRetries int, timeout time.Duration) *ErrorDetails
WithRecovery adds recovery details to the error details
func (*ErrorDetails) WithSystem ¶ added in v1.2.0
func (ed *ErrorDetails) WithSystem(os, arch string, memory, diskSpace int64, processID int) *ErrorDetails
WithSystem adds system details to the error details
func (*ErrorDetails) WithTemplatePath ¶ added in v1.2.0
func (ed *ErrorDetails) WithTemplatePath(path string) *ErrorDetails
WithTemplatePath adds template path information to the error details
func (*ErrorDetails) WithValidation ¶ added in v1.2.0
func (ed *ErrorDetails) WithValidation(rule string, expected, actual interface{}) *ErrorDetails
WithValidation adds validation details to the error details
type LogField ¶ added in v1.3.0
type LogField struct {
Key string
Value interface{}
}
LogField represents a key-value pair for structured logging
func NewLogField ¶ added in v1.3.0
NewLogField creates a new log field
type Logger ¶ added in v1.3.0
type Logger interface {
// Debug logs a debug-level message
Debug(ctx context.Context, msg string, fields ...LogField)
// Info logs an info-level message
Info(ctx context.Context, msg string, fields ...LogField)
// Warn logs a warning-level message
Warn(ctx context.Context, msg string, fields ...LogField)
// Error logs an error-level message
Error(ctx context.Context, msg string, fields ...LogField)
}
Logger is a public interface for logging within AutoPDF This allows external consumers (like cartas-backend) to provide their own loggers and see logs from AutoPDF operations (like latexmk commands) in their own logger output
type LoggerAdapter ¶ added in v1.3.0
type LoggerAdapter struct {
// contains filtered or unexported fields
}
LoggerAdapter adapts AutoPDF's public Logger interface to internal ports.Logger This follows Adapter pattern - bridges public API to internal ports
func (*LoggerAdapter) Debug ¶ added in v1.3.0
func (a *LoggerAdapter) Debug(ctx context.Context, msg string, fields ...autopdfports.LogField)
Debug logs a debug-level message
func (*LoggerAdapter) Error ¶ added in v1.3.0
func (a *LoggerAdapter) Error(ctx context.Context, msg string, fields ...autopdfports.LogField)
Error logs an error-level message
func (*LoggerAdapter) Info ¶ added in v1.3.0
func (a *LoggerAdapter) Info(ctx context.Context, msg string, fields ...autopdfports.LogField)
Info logs an info-level message
func (*LoggerAdapter) Warn ¶ added in v1.3.0
func (a *LoggerAdapter) Warn(ctx context.Context, msg string, fields ...autopdfports.LogField)
Warn logs a warning-level message
type NoOpLoggerAdapter ¶ added in v1.3.0
type NoOpLoggerAdapter struct{}
NoOpLoggerAdapter is a no-op logger implementation for when no logger is provided
func (*NoOpLoggerAdapter) Debug ¶ added in v1.3.0
func (n *NoOpLoggerAdapter) Debug(ctx context.Context, msg string, fields ...autopdfports.LogField)
Debug does nothing
func (*NoOpLoggerAdapter) Error ¶ added in v1.3.0
func (n *NoOpLoggerAdapter) Error(ctx context.Context, msg string, fields ...autopdfports.LogField)
Error does nothing
func (*NoOpLoggerAdapter) Info ¶ added in v1.3.0
func (n *NoOpLoggerAdapter) Info(ctx context.Context, msg string, fields ...autopdfports.LogField)
Info does nothing
func (*NoOpLoggerAdapter) Warn ¶ added in v1.3.0
func (n *NoOpLoggerAdapter) Warn(ctx context.Context, msg string, fields ...autopdfports.LogField)
Warn does nothing
type RecoveryDetails ¶ added in v1.2.0
type RecoveryDetails struct {
Suggestions []string `json:"suggestions,omitempty"`
Retryable bool `json:"retryable"`
MaxRetries int `json:"max_retries,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
}
RecoveryDetails contains recovery suggestions and information
type SystemDetails ¶ added in v1.2.0
type SystemDetails struct {
OS string `json:"os,omitempty"`
Architecture string `json:"architecture,omitempty"`
Memory int64 `json:"memory,omitempty"`
DiskSpace int64 `json:"disk_space,omitempty"`
ProcessID int `json:"process_id,omitempty"`
}
SystemDetails contains system-specific information
type ValidationDetails ¶ added in v1.2.0
type ValidationDetails struct {
Rule string `json:"rule,omitempty"`
Expected interface{} `json:"expected,omitempty"`
Actual interface{} `json:"actual,omitempty"`
Constraints map[string]interface{} `json:"constraints,omitempty"`
}
ValidationDetails contains validation-specific information
type ValidationUtils ¶ added in v1.2.0
type ValidationUtils struct{}
ValidationUtils provides reusable validation functions These can leverage internal logic from the autopdf application layer
func NewValidationUtils ¶ added in v1.2.0
func NewValidationUtils() *ValidationUtils
NewValidationUtils creates a new ValidationUtils instance
func (*ValidationUtils) CreateRecoverySuggestions ¶ added in v1.2.0
func (vu *ValidationUtils) CreateRecoverySuggestions(category, errorCode string) []string
CreateRecoverySuggestions creates recovery suggestions based on error type
func (*ValidationUtils) GetFileMetadata ¶ added in v1.2.0
func (vu *ValidationUtils) GetFileMetadata(filePath string) (map[string]interface{}, error)
GetFileMetadata extracts file metadata
func (*ValidationUtils) ValidateEngine ¶ added in v1.2.0
func (vu *ValidationUtils) ValidateEngine(engine string) (*ErrorDetails, error)
ValidateEngine validates a LaTeX engine
func (*ValidationUtils) ValidateOutputPath ¶ added in v1.2.0
func (vu *ValidationUtils) ValidateOutputPath(outputPath string) (*ErrorDetails, error)
ValidateOutputPath validates an output file path
func (*ValidationUtils) ValidatePDFContent ¶ added in v1.2.0
func (vu *ValidationUtils) ValidatePDFContent(pdfPath string) (*ErrorDetails, error)
ValidatePDFContent validates PDF content structure
func (*ValidationUtils) ValidatePDFPath ¶ added in v1.2.0
func (vu *ValidationUtils) ValidatePDFPath(pdfPath string) (*ErrorDetails, error)
ValidatePDFPath validates a PDF file path
func (*ValidationUtils) ValidateTemplatePath ¶ added in v1.2.0
func (vu *ValidationUtils) ValidateTemplatePath(templatePath string) (*ErrorDetails, error)
ValidateTemplatePath validates a template file path