sources

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeAuth          = "AUTH_ERROR"
	ErrCodeNotFound      = "NOT_FOUND"
	ErrCodeRateLimit     = "RATE_LIMITED"
	ErrCodeNetwork       = "NETWORK_ERROR"
	ErrCodeInvalidConfig = "INVALID_CONFIG"
)

Common error codes

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// Identity
	ID() string
	Name() string

	// Credentials
	CredentialFields() []CredentialField
	SetCredentials(creds map[string]string)
	ValidateCredentials(ctx context.Context) error

	// Data fetching
	FetchProducts(ctx context.Context) ([]ProductInfo, error)
	FetchDeliveries(ctx context.Context, productID string) ([]DeliveryInfo, error)
	FetchFiles(ctx context.Context, productID, deliveryID string) ([]FileInfo, error)

	// Download
	DownloadFile(ctx context.Context, file FileInfo, dst io.Writer, progress ProgressFunc) error
}

Adapter defines the interface for patent office API adapters

type AdapterConfig added in v0.1.5

type AdapterConfig struct {
	DownloadTimeoutSeconds int
}

AdapterConfig holds configuration passed to adapters that support it

type AdapterError

type AdapterError struct {
	Code    string
	Message string
	Err     error
}

AdapterError represents an error from an adapter

func NewAdapterError

func NewAdapterError(code, message string, err error) *AdapterError

NewAdapterError creates a new adapter error

func (*AdapterError) Error

func (e *AdapterError) Error() string

func (*AdapterError) Unwrap

func (e *AdapterError) Unwrap() error

type ConfigurableAdapter added in v0.1.5

type ConfigurableAdapter interface {
	Configure(cfg AdapterConfig)
}

ConfigurableAdapter is an optional interface for adapters that accept runtime configuration from the application. Adapters that do not need configuration can ignore this interface.

type CredentialDecryptor

type CredentialDecryptor interface {
	DecryptCredentials(ciphertext []byte) ([]byte, error)
}

CredentialDecryptor interface for decrypting credentials

type CredentialDecryptorEncryptor

type CredentialDecryptorEncryptor interface {
	CredentialEncryptor
	CredentialDecryptor
}

CredentialDecryptorEncryptor combines both interfaces for UpdateSource

type CredentialEncryptor

type CredentialEncryptor interface {
	EncryptCredentials(plaintext []byte) ([]byte, error)
}

CredentialEncryptor interface for encrypting credentials

type CredentialField

type CredentialField struct {
	Key      string `json:"key"`
	Label    string `json:"label"`
	Type     string `json:"type"` // "text", "password"
	Required bool   `json:"required"`
	HelpText string `json:"helpText,omitempty"`
}

CredentialField defines a credential input field

type DeliveryInfo

type DeliveryInfo struct {
	ExternalID  string     `json:"externalId"`
	Name        string     `json:"name"`
	PublishedAt time.Time  `json:"publishedAt"`
	ExpiresAt   *time.Time `json:"expiresAt,omitempty"`
}

DeliveryInfo represents delivery/release metadata from an API

type FileInfo

type FileInfo struct {
	ExternalID        string    `json:"externalId"`
	FileName          string    `json:"fileName"`
	FileSize          int64     `json:"fileSize"`
	Checksum          string    `json:"checksum,omitempty"`
	ChecksumAlgorithm string    `json:"checksumAlgorithm,omitempty"`
	DownloadURI       string    `json:"downloadUri"`
	ReleasedAt        time.Time `json:"releasedAt"`
}

FileInfo represents file metadata from an API

type ProductInfo

type ProductInfo struct {
	ExternalID    string `json:"externalId"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	CheckSchedule string `json:"checkSchedule"` // Default cron schedule for this product
}

ProductInfo represents product metadata from an API

type ProgressFunc

type ProgressFunc func(bytesWritten, totalBytes int64)

ProgressFunc is called during file downloads to report progress

type Registry

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

Registry manages source adapters

func NewRegistry

func NewRegistry(db *database.DB, cfg *config.Config) *Registry

NewRegistry creates a new source registry

func (*Registry) Get

func (r *Registry) Get(id string) (Adapter, bool)

Get returns an adapter by ID

func (*Registry) GetSource

func (r *Registry) GetSource(id string) (*SourceInfo, error)

GetSource returns a source by ID with its database state

func (*Registry) List

func (r *Registry) List() []Adapter

List returns all registered adapters

func (*Registry) ListSources

func (r *Registry) ListSources() ([]SourceInfo, error)

ListSources returns all sources with their database state

func (*Registry) LoadCredentialsWithDecryptor

func (r *Registry) LoadCredentialsWithDecryptor(decryptor CredentialDecryptor) error

LoadCredentialsWithDecryptor loads and decrypts credentials for all sources

func (*Registry) Register

func (r *Registry) Register(adapter Adapter)

Register adds an adapter to the registry

func (*Registry) RegisterBuiltinAdapters

func (r *Registry) RegisterBuiltinAdapters(adapters ...Adapter)

RegisterBuiltinAdapters registers the built-in source adapters This is called from main.go to avoid import cycles

func (*Registry) TestCredentials

func (r *Registry) TestCredentials(ctx context.Context, id string, credentials map[string]string) error

TestCredentials tests if the credentials for a source are valid

func (*Registry) UpdateSource

func (r *Registry) UpdateSource(id string, enabled bool, credentials map[string]string, cryptor CredentialDecryptorEncryptor) error

UpdateSource updates source configuration

type SourceInfo

type SourceInfo struct {
	ID               string            `json:"id"`
	Name             string            `json:"name"`
	Enabled          bool              `json:"enabled"`
	HasCredentials   bool              `json:"hasCredentials"`
	LastSyncAt       *time.Time        `json:"lastSyncAt,omitempty"`
	CredentialFields []CredentialField `json:"credentialFields"`
}

SourceInfo contains source metadata and state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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