examples

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleArrayFlattening

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

func ExampleCustomConverter()

ExampleCustomConverter demonstrates custom type conversion

func ExampleDebuggingCapabilities

func ExampleDebuggingCapabilities()

ExampleDebuggingCapabilities demonstrates comprehensive debugging features

func ExampleDebuggingWorkflow

func ExampleDebuggingWorkflow()

ExampleDebuggingWorkflow demonstrates a complete debugging workflow

func ExampleDirectDownload

func ExampleDirectDownload()

ExampleDirectDownload demonstrates direct file download

func ExampleHTTPMiddlewareDebugging

func ExampleHTTPMiddlewareDebugging()

ExampleHTTPMiddlewareDebugging demonstrates HTTP middleware debugging capabilities

func ExampleIntegrationWithAutoPDF

func ExampleIntegrationWithAutoPDF()

ExampleIntegrationWithAutoPDF demonstrates integration with AutoPDF API

func ExampleLocalStructToPDF

func ExampleLocalStructToPDF()

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

func ExampleMalformedConfigHandling

func ExampleMalformedConfigHandling()

ExampleMalformedConfigHandling demonstrates error handling for malformed configurations

func ExampleNestedStructs

func ExampleNestedStructs()

ExampleNestedStructs demonstrates nested struct handling

func ExamplePDFDownload

func ExamplePDFDownload()

ExamplePDFDownload demonstrates how to generate and download PDFs

func ExampleRESTAPIUsage

func ExampleRESTAPIUsage()

ExampleRESTAPIUsage demonstrates how to use the REST API

func ExampleRESTAPIWithPDFGeneration

func ExampleRESTAPIWithPDFGeneration()

ExampleRESTAPIWithPDFGeneration demonstrates using the REST API with PDF generation

func ExampleRequest

func ExampleRequest()

ExampleRequest shows the structure of a watch mode request

func ExampleStructConversion

func ExampleStructConversion()

ExampleStructConversion demonstrates basic struct conversion

func ExampleStructToPDFWorkflow

func ExampleStructToPDFWorkflow()

ExampleStructToPDFWorkflow demonstrates the struct-to-PDF workflow

func ExampleTemplateProcessing

func ExampleTemplateProcessing()

ExampleTemplateProcessing demonstrates template processing with complex variables

func ExampleTemplateValidationErrors

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

func ExampleVariableValidationErrors()

ExampleVariableValidationErrors demonstrates variable validation and error reporting

func ExampleWithErrorHandling

func ExampleWithErrorHandling()

ExampleWithErrorHandling demonstrates proper error handling

func RESTAPIServerExample

func RESTAPIServerExample()

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

func RunAllExamples

func RunAllExamples()

RunAllExamples runs all struct conversion examples

func RunRESTAPIServer

func RunRESTAPIServer()

Example of how to run the server

func WatchModeExample

func WatchModeExample()

WatchModeExample demonstrates how to use watch mode with PDF generation

func WatchModeRESTExample

func WatchModeRESTExample()

WatchModeRESTExample demonstrates how to use watch mode via REST API

Types

type Address

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

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

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

type ConversionOptions

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

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

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

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

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

type CustomFormattable

type CustomFormattable struct {
	Value string
	Type  string
}

func (CustomFormattable) ToAutoPDFVariable

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

type Customer

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

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

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

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

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

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

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

HealthResponse represents the health check response

type InlinedUser

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

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

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

type MockPDFGenerationService struct{}

func (*MockPDFGenerationService) Generate

func (*MockPDFGenerationService) GetSupportedEngines

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

func (*MockPDFGenerationService) GetSupportedFormats

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

func (*MockPDFGenerationService) ValidateRequest

type MockPDFValidator

type MockPDFValidator struct{}

func (*MockPDFValidator) GetMetadata

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

func (*MockPDFValidator) IsValidPDF

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

func (*MockPDFValidator) Validate

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

type MockTemplateService

type MockTemplateService struct{}

Mock services for demonstration

func (*MockTemplateService) GetTemplateVariables

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

func (*MockTemplateService) Process

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

func (*MockTemplateService) ValidateTemplate

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

type MockVariableResolver

type MockVariableResolver struct{}

func (*MockVariableResolver) Flatten

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

func (*MockVariableResolver) Resolve

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

func (*MockVariableResolver) Validate

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

type PDFDownloadClient

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

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

func NewPDFDownloadClient

func NewPDFDownloadClient(baseURL string) *PDFDownloadClient

NewPDFDownloadClient creates a new PDF download client

func (*PDFDownloadClient) DownloadAllFiles

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

DownloadAllFiles downloads all files from a generation response

func (*PDFDownloadClient) DownloadFile

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

DownloadFile downloads a generated file

func (*PDFDownloadClient) GeneratePDF

GeneratePDF generates a PDF synchronously

func (*PDFDownloadClient) GeneratePDFAsync

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

GeneratePDFAsync generates a PDF asynchronously

func (*PDFDownloadClient) GetGenerationStatus

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

GetGenerationStatus gets the status of an async generation

type PDFGenerationOptions

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

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

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

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

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

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

RESTAPIClient provides a client for the struct converter REST API

func NewRESTAPIClient

func NewRESTAPIClient(baseURL string) *RESTAPIClient

NewRESTAPIClient creates a new REST API client

func (*RESTAPIClient) ConvertStruct

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

ConvertStruct converts a struct using the REST API

func (*RESTAPIClient) ConvertStructFlattened

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

ConvertStructFlattened converts a struct to flattened variables

func (*RESTAPIClient) ConvertStructForTemplate

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

ConvertStructForTemplate converts a struct optimized for templates

func (*RESTAPIClient) GetConverterConfig

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

GetConverterConfig retrieves the current converter configuration

func (*RESTAPIClient) HealthCheck

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

HealthCheck checks the health of the API

func (*RESTAPIClient) PreviewConversion

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

PreviewConversion provides a preview of struct conversion

func (*RESTAPIClient) ValidateStruct

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

ValidateStruct validates a struct for conversion

type RESTDocument

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

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

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

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

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

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

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

StructToPDFClient provides methods for generating PDFs from structs

func NewStructToPDFClient

func NewStructToPDFClient(baseURL string) *StructToPDFClient

NewStructToPDFClient creates a new struct-to-PDF client

func (*StructToPDFClient) GeneratePDFFromStruct

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

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

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

ValidationRequest represents a request to validate a struct

type ValidationResponse

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

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

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

WatchModeManagerAdapter adapts services.WatchModeManager to application.WatchModeManager

func (*WatchModeManagerAdapter) GetActiveWatches

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

func (*WatchModeManagerAdapter) StartWatchMode

func (*WatchModeManagerAdapter) StopAllWatchModes

func (a *WatchModeManagerAdapter) StopAllWatchModes() error

func (*WatchModeManagerAdapter) StopWatchMode

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