backend

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FallbackExtract

func FallbackExtract(html string) string

FallbackExtract does a simple HTML-to-text conversion for when readability fails.

func IsCode

func IsCode(err error, code ErrorCode) bool

func IsRetryableError

func IsRetryableError(err error) bool

func NewBackendError

func NewBackendError(code ErrorCode, backend, operation string, retryable bool, err error) error

func StripInlineTags

func StripInlineTags(content string) string

StripInlineTags removes residual HTML tags that readability may leave behind while preserving non-tag angle bracket text (emails, ABNF, generics).

Types

type Backend

type Backend interface {
	Name() string
	Priority() int
	Available() bool
	Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error)
	Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)
}

type BackendError

type BackendError struct {
	Code      ErrorCode
	Backend   string
	Operation string
	Retryable bool
	Err       error
}

func (*BackendError) Error

func (e *BackendError) Error() string

func (*BackendError) IsRetryable

func (e *BackendError) IsRetryable() bool

func (*BackendError) Unwrap

func (e *BackendError) Unwrap() error

type BrowserBackend

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

func NewBrowserBackend

func NewBrowserBackend(timeout time.Duration) *BrowserBackend

func (*BrowserBackend) Available

func (b *BrowserBackend) Available() bool

func (*BrowserBackend) Name

func (b *BrowserBackend) Name() string

func (*BrowserBackend) Priority

func (b *BrowserBackend) Priority() int

func (*BrowserBackend) Read

func (*BrowserBackend) Search

type DirectBackend

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

func NewDirectBackend

func NewDirectBackend(timeout time.Duration) *DirectBackend

func (*DirectBackend) Available

func (b *DirectBackend) Available() bool

func (*DirectBackend) Name

func (b *DirectBackend) Name() string

func (*DirectBackend) Priority

func (b *DirectBackend) Priority() int

func (*DirectBackend) Read

func (b *DirectBackend) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error)

func (*DirectBackend) Search

type ErrorCode

type ErrorCode string
const (
	ErrAuth      ErrorCode = "auth"
	ErrRateLimit ErrorCode = "rate_limit"
	ErrParse     ErrorCode = "parse"
	ErrUpstream  ErrorCode = "upstream"
	ErrTimeout   ErrorCode = "timeout"
)

type ReadRequest

type ReadRequest struct {
	URL     string
	Timeout time.Duration
	Proxy   string
	Options map[string]string
}

type ReadResponse

type ReadResponse struct {
	URL       string            `json:"url" yaml:"url"`
	Title     string            `json:"title" yaml:"title"`
	Content   string            `json:"content" yaml:"content"`
	Backend   string            `json:"backend" yaml:"backend"`
	FetchedAt time.Time         `json:"fetched_at" yaml:"fetched_at"`
	Metadata  map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	CacheHit  bool              `json:"cache_hit" yaml:"cache_hit"`
}

type Router

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

func NewRouter

func NewRouter(backends []Backend, opts RouterOptions) *Router

func (*Router) Read

func (r *Router) Read(ctx context.Context, preferred string, req *ReadRequest) (*ReadResponse, error)

func (*Router) Search

func (r *Router) Search(ctx context.Context, preferred string, req *SearchRequest) (*SearchResponse, error)

type RouterOptions

type RouterOptions struct {
	FailureWindow    time.Duration
	FailureThreshold int
	Cooldown         time.Duration
}

type SearchRequest

type SearchRequest struct {
	Query   string
	Limit   int
	Timeout time.Duration
	Proxy   string
	Options map[string]string
}

type SearchResponse

type SearchResponse struct {
	Query     string         `json:"query" yaml:"query"`
	Results   []SearchResult `json:"results" yaml:"results"`
	Limit     int            `json:"limit" yaml:"limit"`
	Backend   string         `json:"backend" yaml:"backend"`
	FetchedAt time.Time      `json:"fetched_at" yaml:"fetched_at"`
	CacheHit  bool           `json:"cache_hit" yaml:"cache_hit"`
}

type SearchResult

type SearchResult struct {
	Title   string `json:"title" yaml:"title"`
	URL     string `json:"url" yaml:"url"`
	Snippet string `json:"snippet" yaml:"snippet"`
}

type StealthBackend

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

func NewStealthBackend

func NewStealthBackend(timeout time.Duration) *StealthBackend

func (*StealthBackend) Available

func (b *StealthBackend) Available() bool

func (*StealthBackend) Name

func (b *StealthBackend) Name() string

func (*StealthBackend) Priority

func (b *StealthBackend) Priority() int

func (*StealthBackend) Read

func (*StealthBackend) Search

Jump to

Keyboard shortcuts

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