examples

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleArrayFlattening added in v1.2.2

func ExampleArrayFlattening()

ExampleArrayFlattening demonstrates array and slice handling

func ExampleBuilderPattern

func ExampleBuilderPattern()

ExampleBuilderPattern demonstrates the builder pattern for PDF generation

func ExampleComplexVariables

func ExampleComplexVariables()

ExampleComplexVariables demonstrates how to use complex variables with AutoPDF

func ExampleCustomConverter added in v1.2.2

func ExampleCustomConverter()

ExampleCustomConverter demonstrates custom type conversion

func ExampleDebuggingCapabilities added in v1.2.2

func ExampleDebuggingCapabilities()

ExampleDebuggingCapabilities demonstrates comprehensive debugging features

func ExampleDebuggingWorkflow added in v1.2.2

func ExampleDebuggingWorkflow()

ExampleDebuggingWorkflow demonstrates a complete debugging workflow

func ExampleDirectDownload added in v1.2.2

func ExampleDirectDownload()

ExampleDirectDownload demonstrates direct file download

func ExampleHTTPMiddlewareDebugging added in v1.2.2

func ExampleHTTPMiddlewareDebugging()

ExampleHTTPMiddlewareDebugging demonstrates HTTP middleware debugging capabilities

func ExampleIntegrationWithAutoPDF added in v1.2.2

func ExampleIntegrationWithAutoPDF()

ExampleIntegrationWithAutoPDF demonstrates integration with AutoPDF API

func ExampleLocalStructToPDF added in v1.2.2

func ExampleLocalStructToPDF()

ExampleLocalStructToPDF demonstrates struct-to-PDF conversion using the local API

func ExampleMalformedConfigHandling added in v1.2.2

func ExampleMalformedConfigHandling()

ExampleMalformedConfigHandling demonstrates error handling for malformed configurations

func ExampleNestedStructs added in v1.2.2

func ExampleNestedStructs()

ExampleNestedStructs demonstrates nested struct handling

func ExamplePDFDownload added in v1.2.2

func ExamplePDFDownload()

ExamplePDFDownload demonstrates how to generate and download PDFs

func ExampleRESTAPIUsage added in v1.2.2

func ExampleRESTAPIUsage()

ExampleRESTAPIUsage demonstrates how to use the REST API

func ExampleRESTAPIWithPDFGeneration added in v1.2.2

func ExampleRESTAPIWithPDFGeneration()

ExampleRESTAPIWithPDFGeneration demonstrates using the REST API with PDF generation

func ExampleRequest added in v1.2.2

func ExampleRequest()

ExampleRequest shows the structure of a watch mode request

func ExampleStructConversion added in v1.2.2

func ExampleStructConversion()

ExampleStructConversion demonstrates basic struct conversion

func ExampleStructToPDFWorkflow added in v1.2.2

func ExampleStructToPDFWorkflow()

ExampleStructToPDFWorkflow demonstrates the struct-to-PDF workflow

func ExampleTemplateProcessing

func ExampleTemplateProcessing()

ExampleTemplateProcessing demonstrates template processing with complex variables

func ExampleTemplateValidationErrors added in v1.2.2

func ExampleTemplateValidationErrors()

ExampleTemplateValidationErrors demonstrates template validation and error reporting

func ExampleTemplateVariables

func ExampleTemplateVariables()

ExampleTemplateVariables demonstrates template variable extraction

func ExampleVariableFlattening

func ExampleVariableFlattening()

ExampleVariableFlattening demonstrates variable flattening

func ExampleVariableValidationErrors added in v1.2.2

func ExampleVariableValidationErrors()

ExampleVariableValidationErrors demonstrates variable validation and error reporting

func ExampleWithErrorHandling added in v1.2.2

func ExampleWithErrorHandling()

ExampleWithErrorHandling demonstrates proper error handling

func RESTAPIServerExample added in v1.2.2

func RESTAPIServerExample()

RESTAPIServerExample demonstrates how to set up a complete REST API server with the AutoPDF Struct Converter endpoints

func RunAllExamples added in v1.2.2

func RunAllExamples()

RunAllExamples runs all struct conversion examples

func RunRESTAPIServer added in v1.2.2

func RunRESTAPIServer()

Example of how to run the server

func WatchModeExample added in v1.2.2

func WatchModeExample()

WatchModeExample demonstrates how to use watch mode with PDF generation

func WatchModeRESTExample added in v1.2.2

func WatchModeRESTExample()

WatchModeRESTExample demonstrates how to use watch mode via REST API

Types

type Address added in v1.2.2

type Address struct {
	Street string `autopdf:"street"`
	City   string `autopdf:"city"`
	State  string `autopdf:"state"`
	Zip    string `autopdf:"zip"`
}

Example structs for demonstration

type AsyncPDFGenerationResponse added in v1.2.2

type AsyncPDFGenerationResponse struct {
	Success   bool   `json:"success"`
	RequestID string `json:"request_id"`
	Message   string `json:"message,omitempty"`
	StatusURL string `json:"status_url"`
}

AsyncPDFGenerationResponse represents the response for async PDF generation

type Contact added in v1.2.2

type Contact struct {
	Email   string   `autopdf:"email"`
	Phone   string   `autopdf:"phone"`
	Website *url.URL `autopdf:"website"`
}

type ConversionOptions added in v1.2.2

type ConversionOptions struct {
	TagName        string `json:"tag_name,omitempty"`
	DefaultFlatten bool   `json:"default_flatten,omitempty"`
	OmitEmpty      bool   `json:"omit_empty,omitempty"`
	TimeFormat     string `json:"time_format,omitempty"`
	DurationFormat string `json:"duration_format,omitempty"`
	SliceSeparator string `json:"slice_separator,omitempty"`
}

ConversionOptions represents conversion options

type ConvertStructRequest added in v1.2.2

type ConvertStructRequest struct {
	Data     interface{}            `json:"data"`
	Options  *ConversionOptions     `json:"options,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

ConvertStructRequest represents a request to convert a struct

type ConvertStructResponse added in v1.2.2

type ConvertStructResponse struct {
	Variables map[string]interface{} `json:"variables"`
	Metadata  map[string]interface{} `json:"metadata"`
	Success   bool                   `json:"success"`
	Message   string                 `json:"message,omitempty"`
}

ConvertStructResponse represents the response from struct conversion

type ConverterConfigResponse added in v1.2.2

type ConverterConfigResponse struct {
	TagName         string   `json:"tag_name"`
	DefaultFlatten  bool     `json:"default_flatten"`
	OmitEmpty       bool     `json:"omit_empty"`
	TimeFormat      string   `json:"time_format"`
	DurationFormat  string   `json:"duration_format"`
	SliceSeparator  string   `json:"slice_separator"`
	RegisteredTypes []string `json:"registered_types"`
	ConverterCount  int      `json:"converter_count"`
}

ConverterConfigResponse represents the current converter configuration

type CustomDocument added in v1.2.2

type CustomDocument struct {
	Title  string            `autopdf:"title"`
	Custom CustomFormattable `autopdf:"custom"`
	Normal string            `autopdf:"normal"`
}

type CustomFormattable added in v1.2.2

type CustomFormattable struct {
	Value string
	Type  string
}

func (CustomFormattable) ToAutoPDFVariable added in v1.2.2

func (cf CustomFormattable) ToAutoPDFVariable() (config.Variable, error)

type Customer added in v1.2.2

type Customer struct {
	Name    string `autopdf:"name"`
	Address string `autopdf:"address"`
	Phone   string `autopdf:"phone"`
	Email   string `autopdf:"email"`
}

Customer represents customer information

type Document added in v1.2.2

type Document struct {
	Title       string                 `autopdf:"title"`
	Author      User                   `autopdf:"author"`
	CreatedAt   time.Time              `autopdf:"created_at"`
	UpdatedAt   *time.Time             `autopdf:"updated_at"`
	Content     string                 `autopdf:"content"`
	Tags        []string               `autopdf:"tags"`
	Categories  []string               `autopdf:"categories,flatten"`
	Metadata    map[string]interface{} `autopdf:"metadata"`
	IsPublished bool                   `autopdf:"is_published"`
}

type ExampleConversionOptions added in v1.2.2

type ExampleConversionOptions struct {
	DoConvert bool    `json:"do_convert,omitempty"`
	Format    string  `json:"format,omitempty"`
	Quality   int     `json:"quality,omitempty"`
	DPI       int     `json:"dpi,omitempty"`
	Scale     float64 `json:"scale,omitempty"`
}

ExampleConversionOptions represents conversion options for images in examples

type FlattenedUser added in v1.2.2

type FlattenedUser struct {
	ID        int       `autopdf:"id"`
	Name      string    `autopdf:"name"`
	Email     string    `autopdf:"email"`
	CreatedAt time.Time `autopdf:"created_at"`
	Address   Address   `autopdf:"address,flatten"`
	Contact   Contact   `autopdf:"contact,flatten"`
	Tags      []string  `autopdf:"tags,flatten"`
	IsActive  bool      `autopdf:"is_active"`
}

type GeneratedFile added in v1.2.2

type GeneratedFile struct {
	Type        string `json:"type"`
	Size        int64  `json:"size"`
	DownloadURL string `json:"download_url"`
	ExpiresAt   string `json:"expires_at,omitempty"`
}

GeneratedFile represents a generated file

type GenerationStatusResponse added in v1.2.2

type GenerationStatusResponse struct {
	RequestID string          `json:"request_id"`
	Status    string          `json:"status"`
	Progress  int             `json:"progress,omitempty"`
	Message   string          `json:"message,omitempty"`
	Files     []GeneratedFile `json:"files,omitempty"`
	Error     string          `json:"error,omitempty"`
}

GenerationStatusResponse represents the status of an async generation

type HealthResponse added in v1.2.2

type HealthResponse struct {
	Status    string `json:"status"`
	Timestamp string `json:"timestamp"`
	Version   string `json:"version"`
}

HealthResponse represents the health check response

type InlinedUser added in v1.2.2

type InlinedUser struct {
	ID        int       `autopdf:"id"`
	Name      string    `autopdf:"name"`
	Email     string    `autopdf:"email"`
	CreatedAt time.Time `autopdf:"created_at"`
	Address   Address   `autopdf:"address,inline"`
	Contact   Contact   `autopdf:"contact,inline"`
	Tags      []string  `autopdf:"tags,flatten"`
	IsActive  bool      `autopdf:"is_active"`
}

type Invoice added in v1.2.2

type Invoice struct {
	InvoiceNumber string     `autopdf:"invoice_number"`
	IssueDate     time.Time  `autopdf:"issue_date"`
	DueDate       time.Time  `autopdf:"due_date"`
	Vendor        Vendor     `autopdf:"vendor"`
	Customer      Customer   `autopdf:"customer"`
	Items         []LineItem `autopdf:"items"`
	Subtotal      float64    `autopdf:"subtotal"`
	Tax           float64    `autopdf:"tax"`
	Total         float64    `autopdf:"total"`
	Notes         string     `autopdf:"notes"`
}

Invoice represents a simple invoice structure

type LineItem added in v1.2.2

type LineItem struct {
	Description string  `autopdf:"description"`
	Quantity    int     `autopdf:"quantity"`
	UnitPrice   float64 `autopdf:"unit_price"`
	Total       float64 `autopdf:"total"`
}

LineItem represents an invoice line item

type MockPDFGenerationService added in v1.2.2

type MockPDFGenerationService struct{}

func (*MockPDFGenerationService) Generate added in v1.2.2

func (*MockPDFGenerationService) GetSupportedEngines added in v1.2.2

func (m *MockPDFGenerationService) GetSupportedEngines() []string

func (*MockPDFGenerationService) GetSupportedFormats added in v1.2.2

func (m *MockPDFGenerationService) GetSupportedFormats() []string

func (*MockPDFGenerationService) ValidateRequest added in v1.2.2

type MockPDFValidator added in v1.2.2

type MockPDFValidator struct{}

func (*MockPDFValidator) GetMetadata added in v1.2.2

func (m *MockPDFValidator) GetMetadata(pdfPath string) (generation.PDFMetadata, error)

func (*MockPDFValidator) IsValidPDF added in v1.2.2

func (m *MockPDFValidator) IsValidPDF(pdfPath string) bool

func (*MockPDFValidator) Validate added in v1.2.2

func (m *MockPDFValidator) Validate(pdfPath string) error

type MockTemplateService added in v1.2.2

type MockTemplateService struct{}

Mock services for demonstration

func (*MockTemplateService) GetTemplateVariables added in v1.2.2

func (m *MockTemplateService) GetTemplateVariables(templatePath string) ([]string, error)

func (*MockTemplateService) Process added in v1.2.2

func (m *MockTemplateService) Process(ctx context.Context, templatePath string, variables map[string]string) (string, error)

func (*MockTemplateService) ValidateTemplate added in v1.2.2

func (m *MockTemplateService) ValidateTemplate(templatePath string) error

type MockVariableResolver added in v1.2.2

type MockVariableResolver struct{}

func (*MockVariableResolver) Flatten added in v1.2.2

func (m *MockVariableResolver) Flatten(variables *generation.TemplateVariables) map[string]string

func (*MockVariableResolver) Resolve added in v1.2.2

func (m *MockVariableResolver) Resolve(variables *generation.TemplateVariables) (map[string]string, error)

func (*MockVariableResolver) Validate added in v1.2.2

func (m *MockVariableResolver) Validate(variables *generation.TemplateVariables) error

type PDFDownloadClient added in v1.2.2

type PDFDownloadClient struct {
	BaseURL    string
	HTTPClient *http.Client
}

PDFDownloadClient provides a client for downloading PDFs and images from AutoPDF API

func NewPDFDownloadClient added in v1.2.2

func NewPDFDownloadClient(baseURL string) *PDFDownloadClient

NewPDFDownloadClient creates a new PDF download client

func (*PDFDownloadClient) DownloadAllFiles added in v1.2.2

func (client *PDFDownloadClient) DownloadAllFiles(response *PDFGenerationResponse, outputDir string) error

DownloadAllFiles downloads all files from a generation response

func (*PDFDownloadClient) DownloadFile added in v1.2.2

func (client *PDFDownloadClient) DownloadFile(requestID, format, outputPath string) error

DownloadFile downloads a generated file

func (*PDFDownloadClient) GeneratePDF added in v1.2.2

GeneratePDF generates a PDF synchronously

func (*PDFDownloadClient) GeneratePDFAsync added in v1.2.2

func (client *PDFDownloadClient) GeneratePDFAsync(req PDFGenerationRequest) (*AsyncPDFGenerationResponse, error)

GeneratePDFAsync generates a PDF asynchronously

func (*PDFDownloadClient) GetGenerationStatus added in v1.2.2

func (client *PDFDownloadClient) GetGenerationStatus(requestID string) (*GenerationStatusResponse, error)

GetGenerationStatus gets the status of an async generation

type PDFGenerationOptions added in v1.2.2

type PDFGenerationOptions struct {
	Engine       string                   `json:"engine,omitempty"`
	OutputFormat string                   `json:"output_format,omitempty"`
	Conversion   ExampleConversionOptions `json:"conversion,omitempty"`
	Debug        bool                     `json:"debug,omitempty"`
	Cleanup      bool                     `json:"cleanup,omitempty"`
	Timeout      int                      `json:"timeout,omitempty"`
}

PDFGenerationOptions represents PDF generation options

type PDFGenerationRequest added in v1.2.2

type PDFGenerationRequest struct {
	TemplatePath string                 `json:"template_path"`
	Variables    map[string]interface{} `json:"variables"`
	Options      *PDFGenerationOptions  `json:"options,omitempty"`
}

PDFGenerationRequest represents a request to generate a PDF

type PDFGenerationResponse added in v1.2.2

type PDFGenerationResponse struct {
	Success     bool              `json:"success"`
	RequestID   string            `json:"request_id"`
	Message     string            `json:"message,omitempty"`
	Files       []GeneratedFile   `json:"files,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
	DownloadURL string            `json:"download_url,omitempty"`
}

PDFGenerationResponse represents the response from PDF generation

type PreviewRequest added in v1.2.2

type PreviewRequest struct {
	Data    interface{}        `json:"data"`
	Options *ConversionOptions `json:"options,omitempty"`
	Limit   int                `json:"limit,omitempty"`
}

PreviewRequest represents a request to preview conversion

type PreviewResponse added in v1.2.2

type PreviewResponse struct {
	Variables map[string]interface{} `json:"variables"`
	Count     int                    `json:"count"`
	Truncated bool                   `json:"truncated"`
	Message   string                 `json:"message,omitempty"`
}

PreviewResponse represents the response from preview conversion

type RESTAPIClient added in v1.2.2

type RESTAPIClient struct {
	BaseURL    string
	HTTPClient *http.Client
}

RESTAPIClient provides a client for the struct converter REST API

func NewRESTAPIClient added in v1.2.2

func NewRESTAPIClient(baseURL string) *RESTAPIClient

NewRESTAPIClient creates a new REST API client

func (*RESTAPIClient) ConvertStruct added in v1.2.2

func (client *RESTAPIClient) ConvertStruct(data interface{}, options *ConversionOptions) (*ConvertStructResponse, error)

ConvertStruct converts a struct using the REST API

func (*RESTAPIClient) ConvertStructFlattened added in v1.2.2

func (client *RESTAPIClient) ConvertStructFlattened(data interface{}, options *ConversionOptions) (*ConvertStructResponse, error)

ConvertStructFlattened converts a struct to flattened variables

func (*RESTAPIClient) ConvertStructForTemplate added in v1.2.2

func (client *RESTAPIClient) ConvertStructForTemplate(data interface{}, options *ConversionOptions) (*ConvertStructResponse, error)

ConvertStructForTemplate converts a struct optimized for templates

func (*RESTAPIClient) GetConverterConfig added in v1.2.2

func (client *RESTAPIClient) GetConverterConfig() (*ConverterConfigResponse, error)

GetConverterConfig retrieves the current converter configuration

func (*RESTAPIClient) HealthCheck added in v1.2.2

func (client *RESTAPIClient) HealthCheck() (*HealthResponse, error)

HealthCheck checks the health of the API

func (*RESTAPIClient) PreviewConversion added in v1.2.2

func (client *RESTAPIClient) PreviewConversion(data interface{}, options *ConversionOptions, limit int) (*PreviewResponse, error)

PreviewConversion provides a preview of struct conversion

func (*RESTAPIClient) ValidateStruct added in v1.2.2

func (client *RESTAPIClient) ValidateStruct(data interface{}) (*ValidationResponse, error)

ValidateStruct validates a struct for conversion

type RESTDocument added in v1.2.2

type RESTDocument struct {
	Title       string     `autopdf:"title"`
	Author      RESTUser   `autopdf:"author"`
	Content     string     `autopdf:"content"`
	CreatedAt   time.Time  `autopdf:"created_at"`
	UpdatedAt   *time.Time `autopdf:"updated_at"`
	URL         url.URL    `autopdf:"url"`
	Tags        []string   `autopdf:"tags,flatten"`
	IsPublished bool       `autopdf:"is_published"`
	Version     int        `autopdf:"version"`
}

type RESTUser added in v1.2.2

type RESTUser struct {
	ID        int       `autopdf:"id"`
	Name      string    `autopdf:"name"`
	Email     string    `autopdf:"email"`
	CreatedAt time.Time `autopdf:"created_at"`
	Profile   struct {
		Bio     string `autopdf:"bio"`
		Website string `autopdf:"website"`
		Avatar  string `autopdf:"avatar"`
	} `autopdf:"profile"`
	Settings struct {
		Theme    string `autopdf:"theme"`
		Language string `autopdf:"language"`
		Privacy  string `autopdf:"privacy"`
	} `autopdf:"settings"`
	Tags []string `autopdf:"tags,flatten"`
}

Example structs for REST API demonstration

type StructGeneratedFile added in v1.2.2

type StructGeneratedFile struct {
	Type        string `json:"type"`
	Size        int64  `json:"size"`
	DownloadURL string `json:"download_url"`
	ExpiresAt   string `json:"expires_at"`
}

StructGeneratedFile represents a generated file in the response

type StructPDFGenerationRequest added in v1.2.2

type StructPDFGenerationRequest struct {
	TemplatePath string            `json:"template_path"`
	Data         interface{}       `json:"data"`
	Options      *StructPDFOptions `json:"options,omitempty"`
}

StructPDFGenerationRequest represents a struct-based PDF generation request

type StructPDFGenerationResponse added in v1.2.2

type StructPDFGenerationResponse struct {
	Success     bool                  `json:"success"`
	RequestID   string                `json:"request_id"`
	Message     string                `json:"message,omitempty"`
	Files       []StructGeneratedFile `json:"files,omitempty"`
	Metadata    map[string]string     `json:"metadata,omitempty"`
	DownloadURL string                `json:"download_url,omitempty"`
	WatchMode   bool                  `json:"watch_mode,omitempty"`
}

StructPDFGenerationResponse represents the API response (from rest/pdf_generation_api.go)

type StructPDFOptions added in v1.2.2

type StructPDFOptions struct {
	Engine    string `json:"engine,omitempty"`
	Debug     bool   `json:"debug,omitempty"`
	WatchMode bool   `json:"watch_mode,omitempty"`
}

StructPDFOptions represents options for struct-based PDF generation

type StructToPDFClient added in v1.2.2

type StructToPDFClient struct {
	BaseURL    string
	HTTPClient *http.Client
}

StructToPDFClient provides methods for generating PDFs from structs

func NewStructToPDFClient added in v1.2.2

func NewStructToPDFClient(baseURL string) *StructToPDFClient

NewStructToPDFClient creates a new struct-to-PDF client

func (*StructToPDFClient) GeneratePDFFromStruct added in v1.2.2

func (client *StructToPDFClient) GeneratePDFFromStruct(templatePath string, data interface{}, options *StructPDFOptions) (*StructPDFGenerationResponse, error)

GeneratePDFFromStruct generates a PDF from a struct using the REST API

type User added in v1.2.2

type User struct {
	ID        int       `autopdf:"id"`
	Name      string    `autopdf:"name"`
	Email     string    `autopdf:"email"`
	CreatedAt time.Time `autopdf:"created_at"`
	Address   Address   `autopdf:"address"`
	Contact   Contact   `autopdf:"contact"`
	Tags      []string  `autopdf:"tags"`
	IsActive  bool      `autopdf:"is_active"`
}

type ValidationRequest added in v1.2.2

type ValidationRequest struct {
	Data interface{} `json:"data"`
}

ValidationRequest represents a request to validate a struct

type ValidationResponse added in v1.2.2

type ValidationResponse struct {
	Valid    bool     `json:"valid"`
	Errors   []string `json:"errors,omitempty"`
	Warnings []string `json:"warnings,omitempty"`
}

ValidationResponse represents the response from struct validation

type Vendor added in v1.2.2

type Vendor struct {
	Name    string `autopdf:"name"`
	Address string `autopdf:"address"`
	Phone   string `autopdf:"phone"`
	Email   string `autopdf:"email"`
}

Vendor represents vendor information

type WatchModeManagerAdapter added in v1.2.2

type WatchModeManagerAdapter struct {
	// contains filtered or unexported fields
}

WatchModeManagerAdapter adapts services.WatchModeManager to application.WatchModeManager

func (*WatchModeManagerAdapter) GetActiveWatches added in v1.2.2

func (a *WatchModeManagerAdapter) GetActiveWatches() map[string]generation.WatchInstanceInfo

func (*WatchModeManagerAdapter) StartWatchMode added in v1.2.2

func (*WatchModeManagerAdapter) StopAllWatchModes added in v1.2.2

func (a *WatchModeManagerAdapter) StopAllWatchModes() error

func (*WatchModeManagerAdapter) StopWatchMode added in v1.2.2

func (a *WatchModeManagerAdapter) StopWatchMode(watchID string) error

Jump to

Keyboard shortcuts

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