sdk

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 48 Imported by: 0

Documentation

Overview

Package sdk provides the public API for pdf-forge. Users interact exclusively with this package to configure and run the engine.

Index

Constants

View Source
const (
	ValueTypeString = entity.ValueTypeString
	ValueTypeNumber = entity.ValueTypeNumber
	ValueTypeBool   = entity.ValueTypeBool
	ValueTypeTime   = entity.ValueTypeTime
	ValueTypeTable  = entity.ValueTypeTable
	ValueTypeImage  = entity.ValueTypeImage
	ValueTypeList   = entity.ValueTypeList
)

ValueType constants (used by Injectors)

View Source
const (
	InjectableDataTypeText     = entity.InjectableDataTypeText
	InjectableDataTypeNumber   = entity.InjectableDataTypeNumber
	InjectableDataTypeDate     = entity.InjectableDataTypeDate
	InjectableDataTypeCurrency = entity.InjectableDataTypeCurrency
	InjectableDataTypeBoolean  = entity.InjectableDataTypeBoolean
	InjectableDataTypeImage    = entity.InjectableDataTypeImage
	InjectableDataTypeTable    = entity.InjectableDataTypeTable
	InjectableDataTypeList     = entity.InjectableDataTypeList
)

InjectableDataType constants (used by WorkspaceInjectableProvider)

View Source
const (
	ListSymbolBullet = entity.ListSymbolBullet
	ListSymbolNumber = entity.ListSymbolNumber
	ListSymbolDash   = entity.ListSymbolDash
	ListSymbolRoman  = entity.ListSymbolRoman
	ListSymbolLetter = entity.ListSymbolLetter
)

List symbol constants

Variables

View Source
var (
	StringValue    = entity.StringValue
	NumberValue    = entity.NumberValue
	BoolValue      = entity.BoolValue
	TimeValue      = entity.TimeValue
	TableValueData = entity.TableValueData
	ImageValue     = entity.ImageValue
	ListValueData  = entity.ListValueData
)

Value constructors

View Source
var (
	NewTableValue = entity.NewTableValue
	Cell          = entity.Cell
	CellWithSpan  = entity.CellWithSpan
	EmptyCell     = entity.EmptyCell
)

Table helpers

View Source
var (
	NewListValue   = entity.NewListValue
	ListItemValue  = entity.ListItemValue
	ListItemNested = entity.ListItemNested
)

List helpers

View Source
var (
	StringPtr = entity.StringPtr
	IntPtr    = entity.IntPtr
)

Pointer helpers

Functions

func RunMigrations

func RunMigrations(configFilePath string) error

RunMigrations is a standalone function that runs migrations with the given config file.

Types

type Engine

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

Engine is the main entry point for pdf-forge. Create with New(), register extensions, then call Run().

func New

func New(opts ...Option) *Engine

New creates a new Engine with the given options.

func (*Engine) GetRenderAuthenticator

func (e *Engine) GetRenderAuthenticator() port.RenderAuthenticator

GetRenderAuthenticator returns the registered render authenticator, or nil if not set.

func (*Engine) OnShutdown

func (e *Engine) OnShutdown(fn func(ctx context.Context) error) *Engine

OnShutdown registers a hook that runs AFTER HTTP server stops, BEFORE exit. Hooks run synchronously in REVERSE registration order (LIFO). Use to gracefully stop background processes started in OnStart.

func (*Engine) OnStart

func (e *Engine) OnStart(fn func(ctx context.Context) error) *Engine

OnStart registers a hook that runs AFTER config/preflight, BEFORE HTTP server starts. Hooks run synchronously in registration order. For background processes (schedulers, workers), spawn a goroutine inside the hook.

func (*Engine) RegisterInjector

func (e *Engine) RegisterInjector(inj port.Injector) *Engine

RegisterInjector adds a custom injector to the engine. Multiple injectors can be registered.

func (*Engine) RegisterMapper deprecated

func (e *Engine) RegisterMapper(m port.RequestMapper) *Engine

Deprecated: Use SetMapper instead.

func (*Engine) Run

func (e *Engine) Run() error

Run starts the engine: loads config, runs preflight checks, initializes all components, and starts the HTTP server. Blocks until shutdown signal (SIGINT/SIGTERM).

func (*Engine) RunMigrations

func (e *Engine) RunMigrations() error

RunMigrations loads config and applies all pending database migrations.

func (*Engine) SetInitFunc

func (e *Engine) SetInitFunc(fn port.InitFunc) *Engine

SetInitFunc sets the global initialization function. Runs once before all injectors on each render request.

func (*Engine) SetMapper

func (e *Engine) SetMapper(m port.RequestMapper) *Engine

SetMapper sets the request mapper for render requests. Only ONE mapper is supported.

func (*Engine) SetRenderAuthenticator

func (e *Engine) SetRenderAuthenticator(auth port.RenderAuthenticator) *Engine

SetRenderAuthenticator sets custom authentication for render endpoints. When set, it replaces OIDC auth for render while panel OIDC continues working.

func (*Engine) SetWorkspaceInjectableProvider

func (e *Engine) SetWorkspaceInjectableProvider(p port.WorkspaceInjectableProvider) *Engine

SetWorkspaceInjectableProvider sets the provider for workspace-specific injectables. If set, the provider's GetInjectables is called when listing injectables, and ResolveInjectables is called during render for provider-owned codes.

func (*Engine) UseAPIMiddleware

func (e *Engine) UseAPIMiddleware(mw gin.HandlerFunc) *Engine

UseAPIMiddleware adds middleware to /api/v1/* routes only. Execution order: Operation → Auth → Identity → Roles → [User API Middleware] → Controller Use for rate limiting, tenant validation, custom authorization, etc.

func (*Engine) UseMiddleware

func (e *Engine) UseMiddleware(mw gin.HandlerFunc) *Engine

UseMiddleware adds middleware to be applied globally to all routes. Execution order: Recovery → Logger → CORS → [User Global Middleware] → Routes Use for logging, tracing, custom headers, etc.

type FormatConfig

type FormatConfig = entity.FormatConfig

FormatConfig defines formatting options for an injector.

type GetInjectablesResult

type GetInjectablesResult = port.GetInjectablesResult

GetInjectablesResult contains the list of available injectables and groups.

type InitFunc

type InitFunc = port.InitFunc

InitFunc is the global initialization function that runs BEFORE all injectors.

type InjectableDataType

type InjectableDataType = entity.InjectableDataType

InjectableDataType represents the data type sent to frontend. Use these constants for ProviderInjectable.DataType.

type InjectableValue

type InjectableValue = entity.InjectableValue

InjectableValue is the typed value returned by an injector.

type Injector

type Injector = port.Injector

Injector defines the interface that users implement to provide custom injectable values.

type InjectorContext

type InjectorContext = entity.InjectorContext

InjectorContext encapsulates context data available to injectors.

type InjectorResult

type InjectorResult = entity.InjectorResult

InjectorResult is the result of resolving an injector.

type ListItem

type ListItem = entity.ListItem

List types

type ListSchema

type ListSchema = entity.ListSchema

List types

type ListSchemaProvider

type ListSchemaProvider = port.ListSchemaProvider

ListSchemaProvider is an optional interface for list injectors to expose list schema.

type ListStyles

type ListStyles = entity.ListStyles

List types

type ListSymbol

type ListSymbol = entity.ListSymbol

List types

type ListValue

type ListValue = entity.ListValue

List types

type MapperContext

type MapperContext = port.MapperContext

MapperContext contains context data for request mapping.

type Middleware

type Middleware = gin.HandlerFunc

Middleware is the function signature for HTTP middleware. Use with UseMiddleware() and UseAPIMiddleware().

type Option

type Option func(*Engine)

Option configures the Engine.

func WithConfig

func WithConfig(cfg *config.Config) Option

WithConfig provides configuration programmatically. Takes precedence over WithConfigFile if both are set.

func WithConfigFile

func WithConfigFile(path string) Option

WithConfigFile loads configuration from a YAML file. Environment variables with DOC_ENGINE_ prefix override YAML values.

func WithDevFrontendURL

func WithDevFrontendURL(url string) Option

WithDevFrontendURL sets a development frontend URL. When set, the engine proxies requests to this URL instead of serving embedded assets. Use this during frontend development for hot-reload support.

func WithI18nFile

func WithI18nFile(path string) Option

WithI18nFile loads injector translations from a YAML file.

type ProviderFormat

type ProviderFormat = port.ProviderFormat

ProviderFormat represents a format option for an injectable.

type ProviderGroup

type ProviderGroup = port.ProviderGroup

ProviderGroup represents a custom group for organizing injectables.

type ProviderInjectable

type ProviderInjectable = port.ProviderInjectable

ProviderInjectable represents an injectable definition from the provider.

type RenderAuthClaims

type RenderAuthClaims = port.RenderAuthClaims

RenderAuthenticator types for custom render endpoint authentication.

type RenderAuthenticator

type RenderAuthenticator = port.RenderAuthenticator

RenderAuthenticator types for custom render endpoint authentication.

type RequestMapper

type RequestMapper = port.RequestMapper

RequestMapper defines the interface for mapping incoming requests.

type ResolveFunc

type ResolveFunc = port.ResolveFunc

ResolveFunc is the function signature for injector resolution.

type ResolveInjectablesRequest

type ResolveInjectablesRequest = port.ResolveInjectablesRequest

ResolveInjectablesRequest contains parameters for resolving injectable values.

type ResolveInjectablesResult

type ResolveInjectablesResult = port.ResolveInjectablesResult

ResolveInjectablesResult contains the resolved values and any non-critical errors.

type TableCell

type TableCell = entity.TableCell

Table types

type TableColumn

type TableColumn = entity.TableColumn

Table types

type TableRow

type TableRow = entity.TableRow

Table types

type TableSchemaProvider

type TableSchemaProvider = port.TableSchemaProvider

TableSchemaProvider is an optional interface for table injectors to expose column schema.

type TableStyles

type TableStyles = entity.TableStyles

Table types

type TableValue

type TableValue = entity.TableValue

Table types

type ValueType

type ValueType = entity.ValueType

ValueType indicates the type of an injectable value.

type WorkspaceInjectableProvider

type WorkspaceInjectableProvider = port.WorkspaceInjectableProvider

WorkspaceInjectableProvider defines the interface for workspace-specific injectables.

Jump to

Keyboard shortcuts

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