fetch

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Action TypedAction
}

Action is used for JSON marshaling/unmarshaling of polymorphic actions

func NewPDFAction

func NewPDFAction(options PDFActionOptions) Action

NewPDFAction creates a new PDF action

func NewScreenshotAction

func NewScreenshotAction(options ScreenshotActionOptions) Action

NewScreenshotAction creates a new screenshot action

func NewWaitAction

func NewWaitAction(options WaitActionOptions) Action

NewWaitAction creates a new wait action

func (*Action) MarshalJSON

func (a *Action) MarshalJSON() ([]byte, error)

MarshalJSON implements custom marshaling for polymorphic actions

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling for polymorphic actions

type BaseAction

type BaseAction struct {
	Type string `json:"type"`
}

BaseAction contains common fields for all actions

func (BaseAction) GetType

func (a BaseAction) GetType() string

type Client

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

Client defines a client for fetching pages via a remote proxy.

func NewClient

func NewClient(options ClientOptions) *Client

NewClient creates a new client with the given options.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, request *Request) (*Response, error)

Fetch a page using a remote proxy.

type ClientOptions

type ClientOptions struct {
	BaseURL   string        // Optional proxy base URL
	AuthToken string        // Optional authorization token
	Timeout   time.Duration // Optional HTTP timeout
}

ClientOptions defines the options for the client.

type Fetcher

type Fetcher interface {
	Fetch(ctx context.Context, request *Request) (*Response, error)
}

Fetcher defines an interface for fetching pages.

type Link struct {
	URL  string `json:"url"`
	Text string `json:"text,omitempty"`
}

Link represents a link on a page.

type Meta

type Meta struct {
	Tag      string `json:"tag"`
	Name     string `json:"name,omitempty"`
	Content  string `json:"content,omitempty"`
	Charset  string `json:"charset,omitempty"`
	Property string `json:"property,omitempty"`
}

Meta represents a meta tag on a page.

type Metadata

type Metadata struct {
	Title         string `json:"title,omitempty"`
	Description   string `json:"description,omitempty"`
	Language      string `json:"language,omitempty"`
	Keywords      string `json:"keywords,omitempty"`
	Author        string `json:"author,omitempty"`
	Canonical     string `json:"canonical,omitempty"`
	Heading       string `json:"heading,omitempty"`
	Robots        string `json:"robots,omitempty"`
	Image         string `json:"image,omitempty"`
	Icon          string `json:"icon,omitempty"`
	PublishedTime string `json:"published_time,omitempty"`
	Tags          []Meta `json:"tags,omitempty"`
}

Metadata conveys high level information about a page.

type PDFAction

type PDFAction struct {
	BaseAction
	Format string `json:"format,omitempty"` // A4, Letter, Legal, etc.
}

PDFAction generates a PDF of the page

type PDFActionOptions

type PDFActionOptions struct {
	Format string `json:"format,omitempty"` // A4, Letter, Legal, etc.
}

PDFActionOptions represents the options for a PDF action

type Request

type Request struct {
	URL             string            `json:"url"`
	OnlyMainContent bool              `json:"only_main_content,omitempty"`
	IncludeTags     []string          `json:"include_tags,omitempty"`
	ExcludeTags     []string          `json:"exclude_tags,omitempty"`
	MaxAge          int               `json:"max_age,omitempty"`  // milliseconds
	Timeout         int               `json:"timeout,omitempty"`  // milliseconds
	WaitFor         int               `json:"wait_for,omitempty"` // milliseconds
	Fetcher         string            `json:"fetcher,omitempty"`
	Mobile          bool              `json:"mobile,omitempty"`
	Prettify        bool              `json:"prettify,omitempty"`
	Formats         []string          `json:"formats,omitempty"`
	Actions         []Action          `json:"actions,omitempty"`
	Headers         map[string]string `json:"headers,omitempty"`
}

Request defines the JSON payload for fetch requests.

type Response

type Response struct {
	URL        string            `json:"url"`
	StatusCode int               `json:"status_code"`
	Headers    map[string]string `json:"headers"`
	HTML       string            `json:"html,omitempty"`
	Markdown   string            `json:"markdown,omitempty"`
	Screenshot string            `json:"screenshot,omitempty"`
	PDF        string            `json:"pdf,omitempty"`
	Error      string            `json:"error,omitempty"`
	Metadata   Metadata          `json:"metadata,omitempty"`
	Links      []Link            `json:"links,omitempty"`
}

Response defines the JSON payload for fetch responses.

type ScreenshotAction

type ScreenshotAction struct {
	BaseAction
	FullPage bool `json:"full_page,omitempty"`
}

ScreenshotAction triggers a screenshot of the page

type ScreenshotActionOptions

type ScreenshotActionOptions struct {
	FullPage bool `json:"full_page,omitempty"`
}

ScreenshotActionOptions represents the options for a screenshot action

type TypedAction

type TypedAction interface {
	GetType() string
}

TypedAction represents an action to be taken on a page

type WaitAction

type WaitAction struct {
	BaseAction
	Selector string `json:"selector,omitempty"` // Wait for element to appear
	Duration int    `json:"duration,omitempty"` // Wait for specific duration in milliseconds
}

WaitAction waits for a condition or time

type WaitActionOptions

type WaitActionOptions struct {
	Selector string `json:"selector,omitempty"` // Wait for element to appear
	Duration int    `json:"duration,omitempty"` // Wait for specific duration in milliseconds
}

WaitActionOptions represents the options for a wait action

Jump to

Keyboard shortcuts

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