core

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCaptcha = errors.New("Captcha detected")
View Source
var ErrSearchTimeout = errors.New("Timeout. Cannot find element on page")

Functions

func InitLogger

func InitLogger(isVerbose, isDebug bool)

Types

type Browser

type Browser struct {
	BrowserOpts
	// contains filtered or unexported fields
}

func NewBrowser

func NewBrowser(opts BrowserOpts) (*Browser, error)

func (*Browser) Close

func (b *Browser) Close() error

func (*Browser) IsInitialized

func (b *Browser) IsInitialized() bool

Check whether browser instance is already created

func (*Browser) Navigate

func (b *Browser) Navigate(URL string) *rod.Page

Open URL

type BrowserOpts

type BrowserOpts struct {
	IsHeadless    bool          // Use browser interface
	IsLeakless    bool          // Force to kill browser
	Timeout       time.Duration // Timeout
	LanguageCode  string
	WaitRequests  bool          // Wait requests to complete after navigation
	LeavePageOpen bool          // Leave pages and browser open
	WaitLoadTime  time.Duration // Time to wait till page loads
}

func (*BrowserOpts) Check added in v0.2.1

func (o *BrowserOpts) Check()

Initialize browser parameters with default values if they are not set

type Query

type Query struct {
	Text         string
	LangCode     string // eg. EN, ES, RU...
	DateInterval string // format: YYYYMMDD..YYYMMDD - 20181010..20231010
	Filetype     string // File extension to search.
	Site         string // Search site
	Limit        int    // Limit the number of results
}

func (*Query) InitFromContext

func (q *Query) InitFromContext(c *fiber.Ctx) error

func (Query) IsEmpty

func (q Query) IsEmpty() bool

type SearchEngine

type SearchEngine interface {
	Search(Query) ([]SearchResult, error)
	IsInitialized() bool
	Name() string
	GetRateLimiter() *rate.Limiter
}

type SearchEngineOptions added in v0.2.1

type SearchEngineOptions struct {
	RateRequests    int   `mapstructure:"rate_requests"`
	RateTime        int64 `mapstructure:"rate_seconds"`
	RateBurst       int   `mapstructure:"rate_burst"`
	SelectorTimeout int64 `mapstructure:"selector_timeout"` // CSS selector timeout in seconds
}

func (*SearchEngineOptions) GetRatelimit added in v0.2.1

func (o *SearchEngineOptions) GetRatelimit() time.Duration

func (*SearchEngineOptions) GetSelectorTimeout added in v0.2.1

func (o *SearchEngineOptions) GetSelectorTimeout() time.Duration

func (*SearchEngineOptions) Init added in v0.2.1

func (o *SearchEngineOptions) Init()

type SearchResult

type SearchResult struct {
	Rank        int    `json:"rank"`
	URL         string `json:"url"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type Server

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

func NewServer

func NewServer(host string, port int, searchEngines ...SearchEngine) *Server

func (*Server) Listen

func (s *Server) Listen() error

func (*Server) Shutdown

func (s *Server) Shutdown() error

Jump to

Keyboard shortcuts

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