Utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandomUseragent

func GetRandomUseragent(useragents map[string]float32) string

GetRandomUseragent returns a weighted random user agent from a map of user agents with associated weights.

If the input map is nil, falls back default user agents with predefined weights. A source for current user-agents is https://www.useragents.me/

Parameters:

  • useragents (map[string]float32): A map of user agents with associated weights.

Returns:

  • string: The selected user agent based on weighted random selection.

func MillisecondToDuration

func MillisecondToDuration(ms interface{}) time.Duration

MillisecondToDuration converts a time duration in milliseconds to a time.Duration.

The ms argument must be able to be cast as a float64. Negative values will be rounded to 0. The function supports int, float32, and float64 types for the ms argument.

Parameters:

  • ms (interface{}): The time duration in milliseconds, which can be an int, float32, or float64.

Returns:

  • time.Duration: The equivalent time.Duration value.

func RpsToDuration

func RpsToDuration(rps float32) time.Duration

RpsToDuration converts a rate per second (rps) to a time.Duration delay.

If the rate per second is less than or equal to 0, the function returns a time.Duration of 0.

Parameters:

  • rps (float32): The rate per second for which to calculate the time duration delay.

Returns:

  • time.Duration: The calculated time duration delay based on the given rate per second.

func UrlsFromFile

func UrlsFromFile(filename string) ([]*url.URL, error)

UrlsFromFile reads a file containing URLs (one per line) and returns a slice of parsed URL objects.

The function reads the content of the specified file, expecting one URL per line. It trims whitespace from each line and parses it into a URL. The resulting parsed URLs are returned as a slice.

Parameters:

  • filename (string): The name of the file containing URLs.

Returns:

  • []*url.URL: A slice of parsed URL objects.
  • error: An error, if any, encountered during file reading or URL parsing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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