Documentation
¶
Index ¶
- type S
- func (s *S) GetErrors() []error
- func (s *S) GetErrorsCount() int64
- func (s *S) GetRandomURLs(n int) []URL
- func (s *S) GetURLCount() int64
- func (s *S) GetURLs() []URL
- func (s *S) Parse(url string, urlContent *string) (*S, error)
- func (s *S) ParseContext(ctx context.Context, url string, urlContent *string) (*S, error)
- func (s *S) SetFetchTimeout(fetchTimeout uint16) *S
- func (s *S) SetFollow(regexes []string) *S
- func (s *S) SetMaxConcurrency(maxConcurrency int) *S
- func (s *S) SetMaxDepth(maxDepth int) *S
- func (s *S) SetMaxResponseSize(maxResponseSize int64) *S
- func (s *S) SetMultiThread(multiThread bool) *S
- func (s *S) SetRules(regexes []string) *S
- func (s *S) SetStrict(strict bool) *S
- func (s *S) SetUserAgent(userAgent string) *S
- type URL
- type URLChangeFreq
- type URLSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type S ¶
type S struct {
// contains filtered or unexported fields
}
S is a structure that holds various data related to processing URLs. It contains a cfg field of type `config`, which stores configuration settings. The mainURL field of type string represents the main URL being processed. The mainURLContent field of type string stores the content of the main URL. The robotsTxtSitemapURLs field is a slice of strings that contains the URLs present in the robots.txt file's sitemap directive. The sitemapLocations field is a slice of strings that represents the locations of the sitemap files. The urls field is a slice of URL structs that stores the URLs to be processed. The errs field is a slice of errors that holds any encountered errors during processing.
func New ¶
func New() *S
New creates a new instance of the S structure. It initializes the structure with default configuration values and returns a pointer to the created instance.
func (*S) GetErrorsCount ¶
func (*S) GetRandomURLs ¶
GetRandomURLs returns a slice of randomly selected URLs from the S object's URL list. The number of URLs to select is specified by the parameter n. If the S object is nil, an empty slice is returned. The function creates a copy of the original URLs list and randomly selects n URLs from it, removing them to avoid duplicates. The selected URLs are returned as a new slice.
func (*S) GetURLCount ¶
GetURLCount returns the count of URLs in the S struct.
func (*S) Parse ¶
Parse is a method of the S structure. It parses the given URL and its content.
Parse is a backward-compatible wrapper around ParseContext that uses context.Background(). For new code, prefer ParseContext so that callers can propagate cancellation and deadlines.
If the S object has any errors, it returns an error with the message "errors occurred before parsing, see GetErrors() for details". It sets the mainURL field to the given URL and the mainURLContent field to the given URL content. It returns an error if there was an error setting the content. If the URL ends with "/robots.txt", it parses the robots.txt file and fetches URLs from the sitemap files mentioned in the robots.txt. If the URL does not end with "/robots.txt", the mainURLContent is checked and unzipped if necessary, then parsed and fetched. It returns the S structure and nil error if the method was able to complete successfully.
func (*S) ParseContext ¶ added in v0.4.0
ParseContext parses the given URL and its content, honoring the supplied context for cancellation and deadlines.
The context is propagated through every HTTP request issued by the parser (both the initial fetch and the recursive sitemap-index/urlset fetches), so cancelling ctx aborts in-flight downloads and prevents new ones from starting. Already-parsed URLs accumulated in s.urls before cancellation remain available via GetURLs(); the cancellation cause is recorded in the error list and is also returned by ParseContext.
All other semantics match Parse.
func (*S) SetFetchTimeout ¶
SetFetchTimeout sets the fetch timeout for the Sitemap Parser. The fetch timeout determines how long the parser will wait for an HTTP request to complete. It should be specified in seconds as a uint16 value. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetFollow ¶ added in v0.1.3
SetFollow sets the follow patterns using the provided list of regex strings and compiles them into regex objects. Patterns longer than maxRegexPatternLength characters are rejected with an error. Any errors encountered during compilation are appended to the error list in the struct. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetMaxConcurrency ¶ added in v0.4.0
SetMaxConcurrency sets the maximum number of concurrent fetch goroutines used when multi-threaded parsing is enabled. A value of 0 (the default) means unlimited concurrency, preserving the historical behaviour. A positive value caps the number of in-flight HTTP fetches across the recursive sitemap-index traversal, which is recommended for very large sitemap indexes to avoid goroutine and connection blow-up. The value must be greater than or equal to 0; negative values are ignored and an error is recorded. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetMaxDepth ¶ added in v0.3.0
SetMaxDepth sets the maximum recursion depth for following sitemap indexes. A sitemap index may reference other sitemap indexes; this limits how many levels deep the parser will follow. The default is 10. The value must be greater than 0; invalid values are ignored and an error is recorded. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetMaxResponseSize ¶ added in v0.3.0
SetMaxResponseSize sets the maximum allowed HTTP response size in bytes. Responses exceeding this limit will be truncated and may cause parsing errors. The default is 50 MB, matching the sitemaps.org protocol limit. The value must be greater than 0; invalid values are ignored and an error is recorded. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetMultiThread ¶ added in v0.1.2
SetMultiThread sets the multi-threading for the Sitemap Parser. The multi-threading flag determines whether the parser should fetch URLs concurrently using goroutines. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetRules ¶ added in v0.1.3
SetRules sets the rules patterns using the provided list of regex strings and compiles them into regex objects. Patterns longer than maxRegexPatternLength characters are rejected with an error. Any errors encountered during compilation are appended to the error list in the struct. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetStrict ¶ added in v0.3.0
SetStrict enables or disables strict mode for URL validation. In strict mode, all URLs in sitemap <loc> elements must be absolute HTTP(S) URLs on the same host and protocol as the sitemap file, and must not exceed 2048 characters, as required by the sitemaps.org specification. In tolerant mode (default), relative URLs are resolved against the parent sitemap URL. The function returns a pointer to the S structure to allow method chaining.
func (*S) SetUserAgent ¶
SetUserAgent sets the user agent for the Sitemap Parser. The user agent is used for making HTTP requests when parsing and fetching URLs. It should be a string representing the user agent header value. The function returns a pointer to the S structure to allow method chaining.
type URL ¶
type URL struct {
Loc string `xml:"loc"`
LastMod *lastModTime `xml:"lastmod"`
ChangeFreq *URLChangeFreq `xml:"changefreq"`
Priority *float32 `xml:"priority"`
}
URL is a structure of <url> in <urlset>
type URLChangeFreq ¶ added in v0.3.0
type URLChangeFreq string
URLChangeFreq represents the frequency at which a URL should be crawled and indexed. Possible values are: "always", "hourly", "daily", "weekly", "monthly", "yearly", and "never".
const ( // ChangeFreqAlways represents the "always" value for URLChangeFreq. ChangeFreqAlways URLChangeFreq = "always" // ChangeFreqHourly represents the "hourly" value for URLChangeFreq. ChangeFreqHourly URLChangeFreq = "hourly" // ChangeFreqDaily represents the "daily" value for URLChangeFreq. ChangeFreqDaily URLChangeFreq = "daily" // ChangeFreqWeekly represents the "weekly" value for URLChangeFreq. ChangeFreqWeekly URLChangeFreq = "weekly" // ChangeFreqMonthly represents the "monthly" value for URLChangeFreq. ChangeFreqMonthly URLChangeFreq = "monthly" // ChangeFreqYearly represents the "yearly" value for URLChangeFreq. ChangeFreqYearly URLChangeFreq = "yearly" // ChangeFreqNever represents the "never" value for URLChangeFreq. ChangeFreqNever URLChangeFreq = "never" )
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
advanced
command
|
|
|
context
command
|
|
|
getrandomurls
command
|
|
|
geturls
command
|
|
|
maxconcurrency
command
|
|
|
maxresponsesize
command
|
|
|
rules
command
|
|
|
simple
command
|
|
|
strict
command
|